How to delete an image from the client-side?

Our jQuery library supports deleting resources on the client-side for a limited time of 10 minutes after being uploaded. After 10 minutes has passed, the image won't be able to be deleted from the client side, only via authenticated API.

When uploading, set the return_delete_token to true in order to tell Cloudinary to return a deletion token in the upload response, use the returned token to delete the uploaded image using an unauthenticated API request.
This is done with the delete_by_token method (of the jQuery library). 

For more information:
http://cloudinary.com/documentation/upload_images#deleting_client_side_uploaded_images

Have more questions? Submit a request

Comments

  • Avatar
    Despertaweb

    I can't get the delete_token! :'(

    I upload the image this way :

    $scope.uploadImages = function() {
    var folder = '/va/bikes/'+$scope.bike._id;
    cloudinary.openUploadWidget({
    folder: folder,
    cloud_name: 'www-despertaweb-cat',
    upload_preset: 'bikes_preset',
    theme: 'minimal',
    thumbnails: 'img-responsive',
    return_delete_token: true
    },
    function(error, result) {
    console.log('\n\n Result', result);
    for(var i in result){
    $scope.bike.imgs.push(result[i]);
    };
    $scope.$apply();
    });

    };

  • Avatar
    Nadav Ofir

    Hi, it seems that you didn't set the "Return delete token" field to True on your "bikes_preset" upload preset. Could you please verify that?

  • Avatar
    Bryan Byrne

    In case it's useful to a future reader, I was personally finding it difficult to find the API endpoint that would allow me to delete using a delete_token, I found it helpful to reference this code in cloudinary jquery library, https://github.com/cloudinary/cloudinary_js/blob/6eac8e5233e6c04e772dcc0f991d28ae4d668c2a/src/jquery-file-upload.coffee#L14

    In the end it's a POST to 'https://api.cloudinary.com/v1_1/' + cloud_name + '/delete_by_token', with parameters of `public_id` and `token`.

Powered by Zendesk