Automatic image hosting
This use-case will show you how to automatically host your images on Mindbaz when you create your campaign.
Reminder of the functionality on Mindbaz:
- When creating your campaign, in the HTML part, it is possible to ask for the automatic hosting of images. If you decide to use this feature, you will be asked to choose a folder to host the images.
- It is now possible to do this via the API as well.
Fetch Folders
To automatically host the images, we will need the ID of the folder where the images will be uploaded. The api allows you to retrieve the folder list by making a GET call to the following endpoint: https://api.mindbaz.com/api/{idsite}/directories/Image/all
Here is an example of the return that can be retrieved
{
"success": true,
"data": [
{
"id": 1,
"name": "Mon répertoire",
"isSystem": true,
"idParent": 0,
"dirType": "Image"
}
],
"error": "string",
"typeName": "string"
}
We keep the id aside. This will be useful later.
Creating the campaign
Now let's create our campaign. If you want to create a simple campaign, a full documentation is available here
We will see the list of parameters to add if you want to automatically host the images.
Here is the list of new fields:
Name | Description | Type |
---|---|---|
AutoHostPictures | Automatically host images | Boolean |
idDirectory | Identifier of the directory to host the images (-1 for the root) | Integer |
Image management
If you want to automatically host the images, you just have to set the AutoHostPictures parameter to true and fill in the idDirectory with the identifier we retrieved earlier via the call https://api.mindbaz.com/api/{idsite}/directories/Image/all
If automatic hosting is selected, Mindbaz will read the entire HTML of the campaign to find all the images. For each of these images, we will download and host it on our servers.
In addition, Mindbaz will modify your HTML with the new URLs.
We have also modified the feedback to add the status of the images. You will be able to see for each of your images the old url, the new url and the status.
- Allowed extensions are: jpg jpeg png gif svg
- The maximum size of an image cannot exceed 800kb
Be careful, if an image with the same filename already exists in the Mindbaz image directory, it will be automatically deleted before being re-uploaded. And it doesn't matter in which directory it was originally located!
Example
For example, with the following html content
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>Hello [[FIELD.15]] [[FIELD.14]]
<img src="https://www.mindbaz.com/wp-content/uploads/2021/02/ico-mail@2x-124.png" /><br /><img src="https://www.mindbaz.com/wp-content/uploads/2021/02/mindbaz-bleu@2x-540.png" /><br /></body>
</html>
...and an image directory (id 1489) named "campApi", a POST /api/{idsite}/campaigns call must be made with the input parameters
{
"parameters": {
"idConfiguration": 1,
"idTestTarget": 7037,
"mode": 0,
"name": "test API",
"sendingSpeed": 100,
"subject": "Ceci est un test",
"type": 2
},
"htmlContent": "<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">
<html>
<body>Hello [[FIELD.15]] [[FIELD.14]]
<img src=""https://www.mindbaz.com/wp-content/uploads/2021/02/ico-mail@2x-124.png"" /><br /><img src=""https://www.mindbaz.com/wp-content/uploads/2021/02/mindbaz-bleu@2x-540.png"" /><br /></body>
</html>",
"AutoHostPictures" : true,
"idDirectory" : 1489
}
The response in autoHostPicturesResult is :
[{
"currentUrl" : "https://www.mindbaz.com/wp-content/uploads/2021/02/ico-mail@2x-124.png",
"newUrl": "https://imgrp.mindbaz.com/100/campApi/ico-mail@2x-124.png",
"status": "uploaded"
},{
"currentUrl":"https://www.mindbaz.com/wp-content/uploads/2021/02/mindbaz-bleu@2x-540.png" ,
"newUrl" : "https://imgrp.mindbaz.com/100/campApi/mindbaz-bleu@2x-540.png" ,
"status" : "uploaded"
}]
Note that all images are now in the "campApi" directory and that the original subdirectory tree is not preserved.
And therefore, if in your HTML, you have several different images with the same name but in different subdirectories, the images will be imported into the same mindbaz directory and thus will be overwritten in the same file.