使用Multer上传图片-在图片旁边创建了其他Blob

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);
    });
  }
};

在我的快速应用中,我具有以下用于上传图像的代码-这似乎已成功上传了图像,但它还在我的上载文件夹-

使用Multer上传图片-在图片旁边创建了其他Blob

中创建了此数据blob
xuelei4460 回答:使用Multer上传图片-在图片旁边创建了其他Blob

您可以做类似的事情

const storage = multer.diskStorage({
    destination: function (req,file,cb) {
      cb(null,'uploads/')
    },filename: function (req,file.originalname)
    }
  })

  const upload = multer({storage: storage})
本文链接:https://www.f2er.com/3094199.html

大家都在问