Skip to main content

How to upload image from Google Script to Cloudinary

Comments

19 comments

  • Jensen Vembil

    Hi Yakir, Could you help me with a live sample example

    0
  • Yakir Perlin

    Hi, 

    Please see this recording and let me know if you have any further questions.

    https://cl.ly/39750536eb82

     

    Best,

    Yakir

    1
  • Jensen Vembil

    Thanks Yakir.

    1
  • Yo.Ka.

    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.

    0
  • Yakir Perlin

    Hey,

    Here is the code to delete resources by tag:

    var delete_by_tag_option = {
     
    'url': 'https://<API_KEY>:<API_SECRET>@api.cloudinary.com/v1_1/<CLOUD_NAME>/resources/<REOURCE_TYPE>/tags/<TAG_NAME>',
     
    'method' : 'DELETE',
    };
    UrlFetchApp.fetch(delete_by_tag_option);

    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

    0
  • Yo.Ka.

    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);
    }

    0
  • Yakir Perlin

    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

    0
  • Yo.Ka.

    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);

    0
  • Yakir Perlin

    Did you use your API secret and API key?

    0
  • Yo.Ka.

    Of course. But login information is rejected.

    0
  • Yakir Perlin

    This will work:

     

    var API_KEY = "xxxx";
    var API_SECRET = "xxxx";
    var CLOUD = "xxxx"
    var RESOURCE_TYPE = "image";
    var TAG_NAME = "mytag";

    var delete_URL = 'https://api.cloudinary.com/v1_1/'+CLOUD+'/resources/' + RESOURCE_TYPE + '/tags/' + TAG_NAME;


    var encoded = Utilities.base64Encode(API_KEY + ":" + API_SECRET);


    var options = {

    'method':'DELETE',
    'headers': {
    'Authorization':'Basic '+encoded

    }

    }


    var result = UrlFetchApp.fetch(delete_URL, options);
    var strFrmFbObj = result.getContentText();
    Logger.log("Result of Delete request: " + strFrmFbObj);
     
     
    The keys should be in the header, sorry for that. 
     
    Best,
    Yakir
    0
  • Yo.Ka.

    Hi Yakir,
    Thank you very much.

    I succeeded in bulk deleting by tag!
    A great achievement for my work.

    0
  • Yakir Perlin

    Great! Thanks for the update. Gald that it works for you.

    Best,

    Yakir

    0
  • Yo.Ka.

    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.

    0
  • Shirly Manor

    Hi,

    Can you please share a URL of one of the deleted images?

    Thanks,

    SHirly

    0
  • Yo.Ka.

    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.

    0
  • Shirly Manor

    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

    0
  • Yo.Ka.

    Hi Shirly,

    The method of deleting these images is as follows.

    0
  • Stephen Doyle

    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

    0

Please sign in to leave a comment.