How to delete an image from the client-side?

Follow

Comments

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

    };

    0
    Comment actions Permalink
  • 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?

    0
    Comment actions Permalink
  • 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`.

    1
    Comment actions Permalink
  • Avatar
    Accion

    not work any more

    Return in the header....

    X-Cld-Error:Return delete token parameter is not allowed when using unsigned upload. Only upload_preset,callback,public_id,folder,tags,context,face_coordinates,custom_coordinates upload parameters are allowed.

     

    0
    Comment actions Permalink
  • Avatar
    Aditi Madan

    Hi Accion,

    I could delete the image with the unsigned upload preset "return delete token" set to "true" in Upload Preset on my account.

     

    Could you please verify the unsigned upload preset you are using has "return delete token" set to "true" in media library settings page.

    You can raise a support ticket here - https://support.cloudinary.com/hc/en-us/requests/new if it still doesn't work and I can take a deeper look at the code.

    0
    Comment actions Permalink
  • Avatar
    Hesham

    This "return delete token" set to "true" in Upload Preset on my account. is not available i can't see it at all been searching for hours now on the dashboard nothing. Really unprofessional and even if i want to use the public id to delete i get 401 signature problem. I post my the image signature and public id and api_key but it is not working.:S

    i use URL from browser client 

    0
    Comment actions Permalink
  • Avatar
    Hesham

    Okay i found how to do this return token thingy : 

    1.open dashboard.

    2.click settings then Upload presets:

    3.click edit

    4.go down and choose advanced options 
     
    5.at the end you will find return delete tokens 
    0
    Comment actions Permalink
  • Avatar
    Yakir Perlin

    Hi Hesham, I glad you find the solution. Please let me know if you need any help. Thanks, Yakir

    0
    Comment actions Permalink
  • Avatar
    John Mack

    Do you have any plans or ability to bring this functionality to React?

    0
    Comment actions Permalink
  • Avatar
    Stephen Doyle

    Hi John,

    The strategy here, of requesting a deletion token and using that in a subsequent API call to delete the image after it was uploaded, should work in any client-side framework, including React.

    We don't have specific support for this in the React SDK so you'd need to make an HTTP request to the API endpoint manually: https://cloudinary.com/documentation/upload_images#deleting_client_side_uploaded_assets

    Generally speaking, we don't intend to add support in the client-side SDKs for destructive actions because almost all other cases would require the API secret to be in the application code, which is not recommended for security reasons

    If you'd like assistance with making the API calls from React, please open a support request with information about your current workflow and we'd be happy to advise

    Thanks,

    Stephen

    0
    Comment actions Permalink

Please sign in to leave a comment.