sdk-for-node icon indicating copy to clipboard operation
sdk-for-node copied to clipboard

🐛 Bug Report: Request failed with status code 400 when saving file stream from busboy

Open Edijae opened this issue 3 years ago • 0 comments

👟 Reproduction steps

When i try to save a file stream received on my express server using busboy, it ends up failing.

const bb = busboy({headers:req.headers});
    bb.on('file', async (name,stream,info) =>{

        try {      
            let response = await api.getStorage().createFile(stream,[],[]);
            console.log("file upload response\n" +JSON.stringify(response));
        } catch (error) {
            console.log("failed to save file. "+error.stack); 
        }
        stream.on('data', (data) => {
            console.log(`File [${name}] got ${data.length} bytes`);
          }).on('close', () => {
            console.log(`File [${name}] done`);
          });

    })

    bb.on('field', (name, val, info) => {
        console.log(`Field [${name}]: value: %j`, val);
      });

    bb.on('close', () => {
        console.log(`close called`);
        res.writeHead(200, { 'Connection': 'close' });
      });

      req.pipe(bb);

Error


Error: Request failed with status code 400

    at createError (/app/node_modules/axios/lib/core/createError.js:16:15)

    at settle (/app/node_modules/axios/lib/core/settle.js:17:12)

    at IncomingMessage.handleStreamEnd (/app/node_modules/axios/lib/adapters/http.js:269:11)

    at IncomingMessage.emit (node:events:377:35)

    at endReadableNT (node:internal/streams/readable:1312:12)

    at processTicksAndRejections (node:internal/process/task_queues:83:21)

👍 Expected behavior

one should be able to save the stream directly without first saving it on a temporary file

👎 Actual Behavior

one cannot save the stream

🎲 Appwrite version

Version 0.10.x

💻 Operating system

MacOS

🧱 Your Environment

No response

👀 Have you spent some time to check if this issue has been raised before?

  • [X] I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Edijae avatar Jan 07 '22 21:01 Edijae