Skip to main content

upload_stream timeout

Comments

3 comments

  • Matthijs Koevoets

    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
  • Ido

    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
  • Duke Osain

    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 help
    from 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 help 
     
    0

Post is closed for comments.