V
V
Valeriy Donika2015-11-15 13:44:13
Angular
Valeriy Donika, 2015-11-15 13:44:13

How to save expressjs+nodejs file from Angular?

Hello. I can't find a google solution for my problem.
I use this https://github.com/danialfarid/ng-file-upload
On the server I use multer

var express = require('express');
var router = express.Router();
var multer = require('multer');
var upload = multer({ dest: 'public/uploads/'});

router.post('/', upload.single('file'), function(req, res) {
   console.log(req.file);
   res.status(200).json({ file: req.file});
});
module.exports = router;

But it is not the image that is saved, but something incomprehensible in the folder.
In the console, after sending the code, I see this in the console.
{ fieldname: 'file',
originalname: 'my.jpg',
encoding: '7bit',
mimetype: 'image/jpeg',
destination: '/home/path/mean/public/uploads/',
filename: '8b6256d4af77641c844480f05806e959' ,
path: '/home/path/mean/public/uploads/8b6256d4af77641c844480f05806e959',
size: 19486
}
Do I need to decode the file somehow? If so, how?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valeriy Donika, 2015-11-15
@Valonix

In general, this is how the file was saved

fs.writeFile('public/uploads/image.jpg', req.file.buffer, 'ascii', function (err) {
        if (err) throw err;
        console.log('It\'s saved!');
    });

Well, of course I will replace the file name. I don't know if this is the correct solution, but it works...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question