Hello
I send jpg file encoded in base64 and i want to decode my file from base64 on recieve before saving to hard disk. where i can put my decode function on data?
please help.
best regards
There is a number of different ways to this but to be honest it seems like it would be smarter to do it before you are uploading the file. Why use base64?
The easiest way would be to use the memory store and then decode + save manually.
var upload = multer({ storage: multer.memoryStorage({}) })
app.post('/', upload.single('test'), function (req, res, next) {
var raw = new Buffer(req.file.buffer.toString(), 'base64')
fs.writeFile('/tmp/upload.png', raw, function (err) {
if (err) return next(err)
res.end('Success!')
})
})
Thank you Linus
but i use base64 encoding because my client side code is C++.
On Sat, Aug 29, 2015 at 3:10 PM, Linus Unnebäck [email protected]
wrote:
There is a number of different ways to this but to be honest it seems like
it would be smarter to do it before you are uploading the file. Why use
base64?The easiest way would be to use the memory store and then decode + save
manually.—
Reply to this email directly or view it on GitHub
https://github.com/expressjs/multer/issues/216#issuecomment-136056482.
No problem
I have same problem, but after saving i can`t open the image. just black background and error...
@LinusU Brother,
When using memoryStorage like this var upload = multer({ storage: multer.memoryStorage({}) }) , how does it affect to memory / RAM ? I have a 4GB RAM in my server.
Let's imagine I am saving 4 images one by one.
When i'm saving 4th image, does 1st , 2nd and 3rd images exists in the RAM ? Or does previous images removing automatically when adding new image ?
api.post('/upload_image', upload.single('v_img'), function (req, res, next) { ..............
I have this code. Imagine 2 users are using this method to upload 2 different images at same time.
How does affect with memoryStorage ?
Imagine 2 users are using this method to upload 2 different images at same time.
Both images would then exist in the memory at the same time. I would only recommend using memoryStorage if you have very low limits on file max size.
```app.post('/upload', function (req, res, next) {
var imageBuffer = new Buffer.from(req.body.base64Str, 'base64');
fs.writeFile('/tmp/myfile.png', imageBuffer , function (err) {
if (err) return next(err)
res.send('Successfully saved')
})
})```
Most helpful comment
There is a number of different ways to this but to be honest it seems like it would be smarter to do it before you are uploading the file. Why use base64?
The easiest way would be to use the memory store and then decode + save manually.