Giter VIP home page Giter VIP logo

Comments (20)

taragano avatar taragano commented on August 15, 2024 3

Note that the destroy method is defaulted to be applied for the image resource type. In order to delete 'raw' files, you should also set the resource_type parameter to raw, e.g.,:

cloudinary.uploader.destroy(<public_id>, callback, {invalidate: true, resource_type: "raw"});

from cloudinary_npm.

melitus avatar melitus commented on August 15, 2024 1

Ensure that during the upload that your resource_type is set to "raw". That way, you can set it again to "raw" whenever you want to delete a resource. This is my code for deleting below.


const deleteImage = async publicId => {
  console.log({publicId})

  try {
    const response = await cloudinary.v2.uploader.destroy(publicId, {
      invalidate: true,
      resource_type: "raw"
    })
    console.log({response})

    if (response.result !== 'ok') {
      throw {
        error: new Error(response.result)
      }
    }
  } catch (error) {
    console.trace({error})
    throw error.error
  }
}

It works perfectly

from cloudinary_npm.

callmekatootie avatar callmekatootie commented on August 15, 2024

Note that I am supplying the correct public ID.

from cloudinary_npm.

callmekatootie avatar callmekatootie commented on August 15, 2024

Does this support "resource_type": "auto" too? I use the same method to delete images as well so I am not sure if the public ID is that of an image or a raw file.

from cloudinary_npm.

taragano avatar taragano commented on August 15, 2024

While "resource_type": "auto" works for uploads, it does not work for deletion API calls. The reason for this is that you may have two different images (one image and one raw) with the same public ID. Therefore, you need to specify what type is the file you wish to delete.

from cloudinary_npm.

callmekatootie avatar callmekatootie commented on August 15, 2024

I finally got around to checking this out.

I assume that you mean I need to specify "resource_type": "raw" when deleting files too. However, this does not work. I still get the same error even if I specify the above.

from cloudinary_npm.

taragano avatar taragano commented on August 15, 2024

I'm sorry for my response delay.
If you can please share the specific code you used for deleting the file and the response you got from Cloudinary, it'd help us to understand the issue.

from cloudinary_npm.

callmekatootie avatar callmekatootie commented on August 15, 2024

Closing this ticket. This issue was resolved through Cloudinary Support. Currently invalidations are applied for URLs which don't include the version (http://support.cloudinary.com/entries/23663103-What-are-image-versions-) component. Removing the version from the URL and then deleting it helped.

from cloudinary_npm.

Hellogark avatar Hellogark commented on August 15, 2024

Well, @taragano i'm having the same problem, i've tried with cloduinary v.2 as in the documentation but i'm getting this error Cannot read property 'uploader' of undefined. i'm setting the public id's as the name of the file on upload, so i'm trying to delete a zip file manually in my node.js app, this is the code i'm using to:

 return await cloudinary.uploader.destroy('464ed5c2d1ccbff558f72105768c4079.zip',  {invalidate: true, resource_type: "raw"}, function (err, res) {
            if(err){
                console.log(err);
                return res.status(400).json({
                    ok:false,
                    mensaje: 'Error deleting file',
                    errors:err
                })
            }
            console.log(res);
    })

I'm getting not found as response
{ result: 'not found' }
this is the url /v1561509799/projects/5cae3cf5b35e4d2dac90fcf6/464ed5c2d1ccbff558f72105768c4079.zip the public_id it's supoused to be 464ed5c2d1ccbff558f72105768c4079.zip, i've tried with several paths, but nothing seems to work

from cloudinary_npm.

eyalktCloudinary avatar eyalktCloudinary commented on August 15, 2024

Hi @Hellogark ,
The public_id of the asset is formed of the path of the asset within Cloudinary's cloud, together with the asset's name. Meaning that the public_id of the file is:
projects/5cae3cf5b35e4d2dac90fcf6/464ed5c2d1ccbff558f72105768c4079.zip
Try it out and let me know if that works for you?

return await cloudinary.v2.uploader.destroy('projects/5cae3cf5b35e4d2dac90fcf6/464ed5c2d1ccbff558f72105768c4079.zip', 
    { invalidate: true, resource_type: "raw"}, function (err, res) {
            if(err){
                console.log(err);
                return res.status(400).json({
                    ok:false,
                    mensaje: 'Error deleting file',
                    errors:err
                })
            }
            console.log(res);
    }

Hope this helps.

from cloudinary_npm.

Hellogark avatar Hellogark commented on August 15, 2024

@eyalktCloudinary My bad, just updated my comment, i'm not using cloudinary.v2.uploader.destroy v2 functions seems not working for me, although i'm requiring like this var cloudinary = require('cloudinary').v2; i've tried the public_id but still returning not found. If i use cloudinary.v2.uploader.destroy i'm getting this error message:

TypeError: Cannot read property 'uploader' of undefined
    at app.delete (C:\Users\edmol\Documents\GitHub\backendServer\routes\proyectos.js:478:36)
    at Layer.handle [as handle_request] (C:\Users\edmol\Documents\GitHub\backendServer\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\edmol\Documents\GitHub\backendServer\node_modules\express\lib\router\route.js:137:13)
    at jwt.verify (C:\Users\edmol\Documents\GitHub\backendServer\middlewares\autenticacion.js:21:9)
    at C:\Users\edmol\Documents\GitHub\backendServer\node_modules\jsonwebtoken\verify.js:223:12
    at getSecret (C:\Users\edmol\Documents\GitHub\backendServer\node_modules\jsonwebtoken\verify.js:90:14)
    at Object.module.exports [as verify] (C:\Users\edmol\Documents\GitHub\backendServer\node_modules\jsonwebtoken\verify.js:94:10)
    at exports.verificaToken (C:\Users\edmol\Documents\GitHub\backendServer\middlewares\autenticacion.js:10:9)
    at Layer.handle [as handle_request] (C:\Users\edmol\Documents\GitHub\backendServer\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\edmol\Documents\GitHub\backendServer\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\edmol\Documents\GitHub\backendServer\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\edmol\Documents\GitHub\backendServer\node_modules\express\lib\router\layer.js:95:5)
    at C:\Users\edmol\Documents\GitHub\backendServer\node_modules\express\lib\router\index.js:281:22
    at param (C:\Users\edmol\Documents\GitHub\backendServer\node_modules\express\lib\router\index.js:354:14)
    at param (C:\Users\edmol\Documents\GitHub\backendServer\node_modules\express\lib\router\index.js:365:14)
    at param (C:\Users\edmol\Documents\GitHub\backendServer\node_modules\express\lib\router\index.js:365:14)

from cloudinary_npm.

eyalktCloudinary avatar eyalktCloudinary commented on August 15, 2024

@Hellogark Note that if you're requiring cloudinary like this
var cloudinary = require('cloudinary').v2;,
you do not need to re-specify v2 when calling the uploader.
Try using cloudinary.uploader.destroy ?

from cloudinary_npm.

Hellogark avatar Hellogark commented on August 15, 2024

@eyalktCloudinary yeah, i've tried with cloudinary.uploader.destroy but i'm getting not found as response, i've trided with the whole url too, included the version for the public_id but still getting the same response. I'm executing this code via app.delete with express

from cloudinary_npm.

Hellogark avatar Hellogark commented on August 15, 2024

well, this is strange, i got {result: ok} i had to made a string with template literals var public_id = projects/${idProject}/${body.file.name};
then my code result like this

try {
        
        return await cloudinary.uploader.destroy(public_id,  {invalidate: true, resource_type: "raw"}, function (err, res) {
                 if(err){
                     console.log(err);
                     return res.status(400).json({
                         ok:false,
                         mensaje: 'Error deleting file',
                         errors:err
                     })
                 }
                 console.log(res);
     
         })
    } catch (error) {
        console.log("error "+error)
    }

but if i set the public_id manually as string it doesn't work

from cloudinary_npm.

eyalktCloudinary avatar eyalktCloudinary commented on August 15, 2024

@Hellogark The version is not part of the public_id.
I want to make sure we're on the same page, if you run the following, what is the response?

var cloudinary = require('cloudinary').v2;
return await cloudinary.uploader.destroy('projects/5cae3cf5b35e4d2dac90fcf6/464ed5c2d1ccbff558f72105768c4079.zip', 
    { invalidate: true, resource_type: "raw"}, function (err, res) {
            if(err){
                console.log(err);
                return res.status(400).json({
                    ok:false,
                    mensaje: 'Error deleting file',
                    errors:err
                })
            }
            console.log(res);
    }

In addition, can you provide your cloud name? It'll help me further investigate.

from cloudinary_npm.

Hellogark avatar Hellogark commented on August 15, 2024

I made it work as i said in my coment above, thanks for the help, i taught the public_id was the one i set in my upload options that is just set as the file name with the extension. This is the cloud name dinamycstest

from cloudinary_npm.

eyalktCloudinary avatar eyalktCloudinary commented on August 15, 2024

@Hellogark You're welcome, glad to hear you've worked it out!

from cloudinary_npm.

Enado95 avatar Enado95 commented on August 15, 2024

@Hellogark You're welcome, glad to hear you've worked it out!

HI @eyalktCloudinary i have you exact implementation but i still receive not found see code below:

var cloudinary = require("cloudinary").v2;
require("dotenv").config();

cloudinary.config({
  cloud_name: process.env.CLOUD_NAME,
  api_key: process.env.CLOUD_API_KEY,
  api_secret: process.env.CLOUD_API_SECRET
});

const deleteimage = async () => {
  return await cloudinary.uploader.destroy(
    "folder/mrobompy9ci9xawtmvcv",
    { invalidate: true, resource_type: "raw" },
    function(err, res) {
      if (err) {
        console.log(err);
        return res.status(400).json({
          ok: false,
          mensaje: "Error deleting file",
          errors: err
        });
      }
      console.log(res);
    }
  );
};

deleteimage()

Response:
{ result: 'not found' }

from cloudinary_npm.

alanyong91 avatar alanyong91 commented on August 15, 2024

@melitus I still get result { result: 'not found' } with exact same setup.
publicId is the full URL or folder path?

from cloudinary_npm.

eyalktCloudinary avatar eyalktCloudinary commented on August 15, 2024

@alanyong91 Hey, in general, the publicId is the concatenation of the file's path in Cloudinary and its name. For instance, if a file named "my-asset" resides under the "animals/dogs/" Cloudinary folder path then its publicId would be "animals/dogs/my-asset". Note that when it comes to assets of type raw, the public ID must contain the file extension. Therefore, continuing the example above, if "my-asset" is a ZIP file (i.e of type raw), then its publicId would be "animals/dogs/my-asset.zip".

I hope this helps. If it doesn't, could you please open a support ticket, so we could investigate further? Be sure to specify your cloud name, an example of a file that you aren't able to delete, and the steps you are performing in order to delete it.

from cloudinary_npm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.