[NODE] "TypeError: file.match is not a function" when uploading
Hi
I tried all different signature for uploading file in node.js :
cloudinary.v2.uploader.upload(file, options, callback); // http://cloudinary.com/documentation/image_upload_api_reference#api_example_1
cloudinary.uploader.upload(file, callback, options); // http://cloudinary.com/documentation/node_image_upload
Each time i have an exception :
TypeError: file.match is not a function
at /home/ubuntu/workspace/node_modules/cloudinary/lib/uploader.js:67:34
at call_api (/home/ubuntu/workspace/node_modules/cloudinary/lib/uploader.js:398:22)
at Object.exports.upload (/home/ubuntu/workspace/node_modules/cloudinary/lib/uploader.js:64:12)
at Object.v1_adapter as upload
at Object.<anonymous> (/home/ubuntu/workspace/app.js:88:24)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)
at Module.load (module.js:355:32)
at Function.Module._load (module.js:310:12)
at Module.runMain as _onTimeout
Documentation say this :
The file to upload. Can be a local file path (supported in SDKs only), the actual data (byte array buffer), the Data URI (Base64 encoded), a remote FTP, HTTP or HTTPS URL of an existing file, or an S3 URL (of a whitelisted bucket).
So I try to pass a buffer.
Always the same issue
-
well i didn't remember my that post.
Today i use cloudinary.uploader.upload_stream function. I had no issue with it. See below how i use it with a buffer.
class BufferStream extends stream.Readable {
constructor(buffer, options) {
super(options || {});
this.buffer = buffer;
}
_read(size) {
if (this.buffer.length === 0) {
this.push(null);
} else {
this.push(this.buffer.slice(0, size));
this.buffer = this.buffer.slice(size);
}
}
}var stream = new BufferStream(myFileBuffer);
stream.pipe(cloudinary.uploader.upload_stream(callback));
Post is closed for comments.
Comments
2 comments