const upload = multer({ dest: `${__dirname}/uploads/images` });
app.post(
"/api/users/:id/uploadProfilePic",upload.single("image"),updateProfilePic
);
const updateProfilePic = async (req,res) => {
const userId = req.param("id");
if (userId && isnumber(userId)) {
// When using the "single"
// data come in "req.file" regardless of the attribute "name". *
const tmpPath = req.file.path;
// The original name of the uploaded file
// stored in the variable "originalname". *
const targetPath = `uploads/images/${req.file.originalname}`;
/** A better way to copy the uploaded file. **/
const src = fs.createReadStream(tmpPath);
const dest = fs.createWriteStream(targetPath);
src.pipe(dest);
src.on("end",() => {
res.status(200).send("complete");
});
src.on("error",err => {
res.status(500).send(err);
});
}
};
中创建了此数据blob使用Multer上传图片-在图片旁边创建了其他Blob
•
问答