upload_stream timeout
Hello there,
I have this bit of code for uploading a stream to cloudinary. Problem is: it only works for files upto 50KB or so. Anything larger results in a timeout. I'm on the free plan. Any ideas as to what may be causing this?
const uploadStream = cloudinary.v2.uploader.upload_stream(
{ tags: "test" },
(error, result) => {
console.log("cloudinary returning...");
if (result) {
console.log("result", result);
} else {
console.log("error", error);
}
}
);
const stream = file.createReadStream();
stream.pipe(uploadStream);
thanks,
Matt
-
Sorry, fixed it already. This might be something for your documentation: Works out I had to wrap this in a promise, like so (graphql resolver):
uploadFile: async (_, { upload }) => {
const file = await upload // (using apollo 2.0 upload here)
const uploadToCloudinary = () => {
return new Promise((resolve, reject) => {
const uploadStream = cloudinary.v2.uploader.upload_stream(
{
tags: "test"
},
(error: any, result: any) => {
if (result) {
resolve(result);
} else {
reject(error);
}
}
);
const stream = file.createReadStream();
stream.pipe(uploadStream);
});
};
const result = await uploadToCloudinary();
console.log(result);
}0 -
Hi
Thanks for your patience with the reply.
When we try an upload stream without a promise we also get it to work.
specifically the below code works:
------
var cloudinary = require('cloudinary').v2;
var fs = require('fs');
var stream = cloudinary.uploader.upload_stream(function(error, result){console.log(result, error)});
var file_reader = fs.createReadStream('<path_to_file>').pipe(stream);-------
Hope this helps.
0 -
Hello Ido
Hello, am having similar issue, i tried to follow the example above but is still not work.
Am using apollo graphql to pass body of post and file upload, at the backend i console.log(file) and it shows the result below but i console.log(stream) it gives undefile . am trying to store it cloudinary before storing the link at MongoDb, but is the storing of the file at cloudinary working.
Am having this error "
- TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type undefined"

Thanks for your helpfrom the inform that was console.log(file), what will be the '<path_to_file>' from the line "var file_reader = fs.createReadStream('<path_to_file>').pipe(stream);" ?is stream suppose to undefined ?thanks for your help0
Post is closed for comments.
Comments
3 comments