Can´t resend file with memoryStorage option
See original GitHub issueHi!
I’ve an Express server which expects a file uploaded via form and then sends that file over to another API.
I tested it saving the file to disk and it works perfectly.
const multer = require('multer');
const fs = require('fs');
const request = require('request');
exports.upload = multer({ dest: 'uploads/' }).single('file');
exports.uploadFile = (req, res) => {
const formData = {
name: req.body.name,
file: fs.createReadStream('uploads/' + req.file.filename)
}
const options = {
url: `${path}/nodes`,
formData
}
request.post(options, (err, response, body) => {
if (err) return res.status(400).send({ msg: 'error', err });
return res.status(201).send(response.body);
});
})
.catch(err => res.status(400).send({ msg: 'error', err }));
}
Now, as this is just an intermediate step (for authentication purposes), I don´t really need to save the file to disk, I want to keep it in memory and send it to the other API. So I changed my code:
exports.upload = multer({ storage: multer.memoryStorage() }).single('file');
exports.uploadFile = (req, res) => {
const formData = {
name: req.body.name,
file: req.file.buffer
}
const options = {
url: `${path}/nodes`,
formData
}
request.post(options, (err, response, body) => {
if (err) return res.status(400).send({ msg: 'error', err });
return res.status(201).send(response.body);
});
})
.catch(err => res.status(400).send({ msg: 'error', err }));
}
But this is not working. I tried many things, encode it to base64 before sending it, create a bufferStream with new stream.PassThrough()
but nothing seems to work. Am I doing anything wrong here?
Thanks
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:5 (2 by maintainers)
Top Results From Across the Web
how to upload file saved in memory by multer to another API
I've found the way to upload files with multer through buffer and not storing locally... Here is my code.... var multer = require('multer'); ......
Read more >Messages Displayed on the Control Panel When Using the ...
Message Cause Solution
"Authentication has failed." The machine cannot perform authentication. Contact the...
"Now loading WSD... Please wait." WSD scanner function is being prepared. Wait...
Read more >This version has been deprecated - multer - npm
MemoryStorage. The memory storage engine stores the files in memory as Buffer objects. It doesn't have any options. var storage = multer.
Read more >Ricoh C6503-7503 User Guide.pdf
See "Basic Procedure for Saving Scan Files on a Memory Storage Device", ... You can store files scanned in copier, facsimile, printer, or...
Read more >selenium-wire - PyPI
Selenium Wire also has it's own options that can be passed in the ... Note that driver.wait_for_request() doesn't make a request, it just...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@davidanaya did you ever find solution for this? im doing a very similar thing except using
FormData
to “forward” the upload to a different api. It works perfectly fine if I use LocalStorage but when using MemoryStorage and using thefile.buffer
it doesnt seem to workI’m having the same issue. Did you find a solution?