Since Google Script has no native support for FormData variable, we need to use a simple JSON object, for example:
var formData = {
'file': '<file_path>',
'upload_preset': '<upload_preset>'
};
var options = {
'method' : 'post',
'payload' : formData
};
UrlFetchApp.fetch('https://api.cloudinary.com/v1_1/<cloud_name>/image/upload/', options);
Comments
19 comments
Hi Yakir, Could you help me with a live sample example
Hi,
Please see this recording and let me know if you have any further questions.
https://cl.ly/39750536eb82
Best,
Yakir
Thanks Yakir.
Hello, Yakir.
I am a Japanese who cannot speak English.
I really want to know.
Please tell me the script of bulk deletion by tag in Google Apps Script.
Hey,
Here is the code to delete resources by tag:
You can read more about that here:
https://cloudinary.com/documentation/admin_api#delete_resources_by_tags
Please let me know if it works for you.
Best,
Yakir
Hi Yakir,
Thank you for your reply.
The following error appears in the line of UrlFetchApp.fetch.
Invalid argument: http://[object%20Object]
function cloudinary_bulkDeletionByTag(tags) {
var API_KEY = "xxxx";
var API_SECRET = "xxxxxxxxxxxx";
var REOURCE_TYPE = "image";
var TAG_NAME = "mytag";
var delete_by_tag_option = {
'url': 'https://'+ API_KEY +':'+ API_SECRET +'@api.cloudinary.com/v1_1/xxxxxxxxxxxx/resources/'+ REOURCE_TYPE +'/tags/'+ TAG_NAME,
'method': 'DELETE'
};
UrlFetchApp.fetch(delete_by_tag_option);
}
Hey,
Please to use this:
var API_KEY = "xxxx";
var API_SECRET = "xxxxxxxxxxxx";
var REOURCE_TYPE = "image";
var TAG_NAME = "mytag";
var url .= 'https://'+ API_KEY +':'+ API_SECRET +'@api.cloudinary.com/v1_1/xxxxxxxxxxxx/resources/'+ REOURCE_TYPE +'/tags/'+ TAG_NAME;
var option = {'method' : 'DELETE'}
UrlFetchApp.fetch(url, options);
BTW, you can find docs about this method here:
https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app.html#fetch(String,Object)
Please let me know if it works for you.
Best,
Yakir
Hi Yakir,
Thank you for your reply.
The following error appears in the line of UrlFetchApp.fetch.
Login information rejected:
https://<API_KEY>:<API_SECRET>@api.cloudinary.com/v1_1/XXXXX/resources/image/tags/mytag
---
var API_KEY = "<API_KEY>";
var API_SECRET = "<API_SECRET>";
var RESOURCE_TYPE = "image";
var TAG_NAME = "mytag";
var delete_URL = 'https://'+ API_KEY +':'+ API_SECRET +'@api.cloudinary.com/v1_1/XXXXX/resources/'+ RESOURCE_TYPE +'/tags/'+ TAG_NAME;
var options = { 'method': 'DELETE' }
UrlFetchApp.fetch(delete_URL, options);
Did you use your API secret and API key?
Of course. But login information is rejected.
This will work:
Hi Yakir,
Thank you very much.
I succeeded in bulk deleting by tag!
A great achievement for my work.
Great! Thanks for the update. Gald that it works for you.
Best,
Yakir
Hi Yakir,
Why isn't it completely gone when I delete the image?
I can't upload with the same Public ID, and accessing the URL shows the deleted image.
How do I solve it?
Thank you.
Hi,
Can you please share a URL of one of the deleted images?
Thanks,
SHirly
Hi Shirly,
Thank you for your reply.
The following images were deleted by me.
https://res.cloudinary.com/studiosimply/image/upload/v1578216850/Homepages/eIo_S0aHyfI.jpg
https://res.cloudinary.com/studiosimply/image/upload/v1578216850/Homepages/kWrOmEtXk0k.jpg
https://res.cloudinary.com/studiosimply/image/upload/v1578216850/Homepages/r5GADHqHcz8.jpg
At the time of posting, it disappeared from the dashboard, but the image was visible when accessing the URL.
But if I confirm now, I can't access the URL.
Apparently the image has been deleted.
The image seems to take some time to disappear.
Hi,
In order to provide better feedback, can you please explain how you deleted those images?
The first image uploaded again on `January 7th 2020, 01:31:35 CT` and exists and working on my end.
Looking forward to your response,
Shirly
Hi Shirly,
The method of deleting these images is as follows.
Hi,
When you use the bulk delete functionality, that doesn't automatically send invalidation requests to the CDN to purge the CDN cache for the deleted images, so they may still be accessible via the CDN until the cache expires.
If you need the CDN cache to be invalidated immediately, on any of our paid plans, we can enable an option that allows invalidations to be sent when you use the bulk delete API.
Also, on any plan including our free plans, invalidations can be sent you can delete files individually. This is automatic if you delete via the UI and if you're using the destroy() API method the 'invalidate' parameter can be used to request invalidation.
To help you fix this specific example, I've invalidated the CDN cache for all resources in your account, so the deleted files should no longer be accessible
Regards,
Stephen
Please sign in to leave a comment.