This is temp, how to resize image before upload using multer
class Resize {
constructor(folder) {
this.folder = folder;
}
async save(files) {
let filenames = [];
for(let file of files){
let filename = Resize.filename();
let filepath = this.filepath(filename);
await sharp(file.buffer)
.resize(500, 500, { // size image 300x300
fit: sharp.fit.inside,
withoutEnlargement: true
})
.toFile(filepath);
filenames.push(filename);
}
return filenames;
}
static filename() {
// random file name
return `${uuidv4()}.png`;
}
filepath(filename) {
return path.resolve(`${this.folder}/${filename}`)
}
}
This is temp, how to handle resize multi files or option multer for resize file before upload
You can't really resize a file before uploading it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.