это мой node.js app.js код конца:
const sharp = require('sharp');
app.post('/images', upload.single('file'), function (req, res, next) {
sharp(req.file.path).resize(20,20).toFile(req.file.path, (err, info) => { console.log(err) });
res.send(req.file.filename);
})
res.send (req.file.filename) работает, но размер картинки не изменяется, я не знаю почему.
Это мой мультер app.js params:
var multer = require('multer');
var storage = multer.diskStorage({
destination: function (req, file, cb) {
cb(null, './uploads/')
},
filename: function (req, file, cb) {
cb(null, file.originalname+ '-' + Date.now()+'.jpg')
}
});
var upload = multer({ storage: storage });
Это ошибка:
Error: Cannot use same file for input and output
at Sharp.toFile (C:\UwAmp\www\geretonequipesnode\node_modules\sharp\lib\output.js:43:32)
at C:\UwAmp\www\geretonequipesnode\app.js:77:40
at Layer.handle [as handle_request] (C:\UwAmp\www\geretonequipesnode\node_modules\express\lib\router\layer.js:95:5)
at next (C:\UwAmp\www\geretonequipesnode\node_modules\express\lib\router\route.js:137:13)
at Immediate._onImmediate (C:\UwAmp\www\geretonequipesnode\node_modules\multer\lib\make-middleware.js:53:37)
at runCallback (timers.js:706:11)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
Спасибо
РЕДАКТИРОВАТЬ: разрешается следующим образом:
var fs = require('fs');
app.post('/images', upload.single('file'), function (req, res, next) {
sharp(req.file.path).resize(20,20).toBuffer(function(err, buffer) {
fs.writeFile(req.file.path, buffer, function(e) {
});
});
res.send(req.file.filename);
})