Destroying images uploaded though signed forms

Comments

6 comments

  • Avatar
    Itay Taragano

    Hi Doncello,

    I'd be happy to take a deeper look at the specific requests you tried and understand what specific error message did you get when trying to do so. If privacy is an issue, please feel free to contact us directly with more details.

    In general, note that the 'destroy' API needs to be authenticated by a signature that's based on your account's api_secret, which must be kept hidden in your backend, rather than on your frontend. Here are a few recommend flows for this:

    1. Either the user can ask to delete a resource, which invokes a request to your server, and then your server would make the 'destroy' call.
    2. Have your server pre-generate the page with the payload (incl. the signature) that can be used for a client-side 'destroy' call (note that the signature can be used within one hour)
    3. Implement our client-side delete token, which is valid for 10 minutes from the upload time.

    If none of these work for you, please feel free to contact us via a support ticket, and we'll be happy to understand your use-case better to understand the most optimal approach.

    0
    Comment actions Permalink
  • Avatar
    doncello

    Dear Itay,

    As I wrote in my question I just tried these method:

    await cloudinary.uploader.destroy(filename)
    await cloudinary.v2.uploader.destroy(filename)
     
    and I guess they failed because they weren't autenticated with api_secret.

    Asuming that I want to follow the 1st method. Is there any documentation or sample script regarding authentication of the 'destroy' API and then making 'destroy' call from the server?

    0
    Comment actions Permalink
  • Avatar
    Eric Pasos

    Hi Doncello,

    When uploading authenticated assets in your account that has its `delivery type` set as `authenticated` instead of the default value of `upload`, deleting the asset from your account will require you to provide the optional parameter (i.e. type = "authenticated") in your destroy method or delete_resources method.

    For example: 

    cloudinary.uploader.destroy("sample.jpg", type = "authenticated")

    or

    cloudinary.api.delete_resources("sample.jpg", type = "authenticated")

    If you still cannot delete the files due to some other reasons, you may raise a ticket through the support center so we could check your account in detail and we'll be able to provide you some recommendations.

    0
    Comment actions Permalink
  • Avatar
    doncello

    Hi Eric,

    I think there is misunderstanding; what I can't remove is not images that has 'delivery type' set as 'authenticated'. I can't delete the images which are signed client side before uploaded. There is no access restriction on them. And i still can't delete them with the 

    cloudinary.uploader.destroy("sample.jpg")

    method. Should I still contact the support?

    I've checked the error log and I'm getting 'not found' error altough the file is there

    `

    [ 'leqdq1gmjind7sgrbzqy' ] to be deleted
    {
    deleted: { leqdq1gmjind7sgrbzqy: 'not_found' },
    deleted_counts: { leqdq1gmjind7sgrbzqy: { original: 0, derived: 0 } },
    partial: false,
    rate_limit_allowed: 500,
    rate_limit_reset_at: 2021-09-06T09:00:00.000Z,
    rate_limit_remaining: 499
    } undefined

    `

    0
    Comment actions Permalink
  • Avatar
    doncello

    It seems that destroy method needs folder name to be included. After adding folder name problem solved.

    0
    Comment actions Permalink
  • Avatar
    Eric Pasos

    Hi Doncello,

    You are correct. All assets that are in a folder or subfolder should have the public_id include these full path from the root location. For example (i.e. using a public file):

    https://res.cloudinary.com/demo/image/upload/folderA/subfolderB/sample_asset.jpg

    means that the sample_asset.jpg is inside the 2 folders from the root_dir (i.e. Media Library Home): folderA/subfolderB/

    And to delete this, you can do it like:

    cloudinary.uploader.destroy("folderA/subfolderB/sample_asset.jpg")
    0
    Comment actions Permalink

Please sign in to leave a comment.