I'm trying to send the upload file to aws s3. For this, I upload the files with multer
and I resize them with graphicsmagick
.
In my aws s3 arborescence, I'm trying to made this :
user_id
- informations
- cover.jpg
- profil.jpg
- post_id
- pic_one
- pic_two
So I got my route :
router.post('/', [ auth.isAuthenticated(),
multer({ dest: 'client/assets/images/',
onFileUploadComplete : function(file, req, res){
console.log('multer File Upload Complete End !');
}
})
], controller.create);
And the associate controller :
exports.create = function(req, res) {
Post.create(req.body, function(err, post) {
if(err) { return handleError(res, err); }
var folder = req.user._id + '/' + post._id + '/';
console.log('I'm here!');
for (var index = 0; index < post.pictures.length; index++) {
gm('../../../client/assets/images/' + post.pictures[index]).resize(550, 550);
if (req.files.file instanceof Array) aws_service.put(folder, req.files.file[index]);
else aws_service.put(folder, req.files.file);
}
}
}
The problem is : the upload complete event is called but my file is not created. So I got an error in my aws_service.
multer File Upload Complete End !
I'm here !
/Users/project/node/node_modules/mongoose/lib/utils.js:413
throw err;
^
Error: ENOENT, no such file or directory '../../client/assets/images/55acf078f09d4489e6e3a3a7cc26166b.jpg'
at Object.fs.openSync (fs.js:438:18)
at Object.fs.readFileSync (fs.js:289:15)
at Object.exports.put (/Users/project//node/server/aws/aws.service.js:12:18)
at Promise.<anonymous> (/Users/project/node/server/api/post/post.controller.js:52:24)
at Promise.<anonymous> (/Users/project/node/node_modules/mongoose/node_modules/mpromise/lib/promise.js:177:8)
at Promise.emit (events.js:95:17)
at Promise.emit (/Users/project/node/node_modules/mongoose/node_modules/mpromise/lib/promise.js:84:38)
at Promise.fulfill (/Users/project/node/node_modules/mongoose/node_modules/mpromise/lib/promise.js:97:20)
at Promise.<anonymous> (/Users/project/node/node_modules/mongoose/lib/model.js:1544:35)
at Promise.<anonymous> (/Users/project/node/node_modules/mongoose/node_modules/mpromise/lib/promise.js:177:8)
>> File "client/assets/images/55acf078f09d4489e6e3a3a7cc26166b.jpg" added.
At the end, we can see >> File "client/assets/images/55acf078f09d4489e6e3a3a7cc26166b.jpg" added.
How can I resolve this?
Aucun commentaire:
Enregistrer un commentaire