"Error: ENOENT" when using cloudinary?


#1

I’m not sure how to get the absolute path to the file… I’m using react-dropzone following this:

but instead of client-side call using superagent, I’m using a method with the cloudinary npm package:

import { Meteor } from 'meteor/meteor';
import cloudinary from 'cloudinary';


cloudinary.config({ 
  cloud_name: 'myname', 
  api_key: 'mykey', 
  api_secret: 'mysecret' 
});

Meteor.methods({
  uploadImg: function(file){
    check(file, String);
    console.log(file); //outsputs 'my-image.jpg'

    cloudinary.uploader.upload(file, function(error, result) {
      if (error) {console.log(error); return;}   //outputs: { error: { [Error: ENOENT, open 'my-image.jpg'] errno: 34, code: 'ENOENT', path: 'my-image.jpg' } }
      console.log('it worked'); 
    });

    return;
  }

});

I was passing the uploadImg method file.name from this object:

{    lastModified:1471614351000
    lastModifiedDate:Fri Aug 19 2016 09:45:51 GMT-0400 (EDT)
    name:"my-image.jpg"
    preview:"blob:http://localhost:3000/b13a29ad-0835-4f2c-b9ce-f53c8387eac3"
    size:51960
    type:"image/jpeg"
    webkitRelativePath : ""
}

#2

Your my-image.jpg doesn’t exist on the file system anywhere, so when you’re calling cloudinary.uploader.upload with that filename, the Cloudinary package can’t find it (hence the “error no entry” message). You’ll likely want to look into using a stream instead. For an idea of how streams can work with Cloudinary, take a look at the lepozepo:cloudinary package’s server.js file. I know you’re using the npm cloudinary package instead, but that source file shows how to use streams with the npm package.