Node.js 使用Multer上载图像-在图像旁边创建附加blob

Node.js 使用Multer上载图像-在图像旁边创建附加blob,node.js,rest,express,multipart,multer,Node.js,Rest,Express,Multipart,Multer,在我的express应用程序中,我有以下上载图像的代码-这似乎成功上载了图像,但它也在我的上载文件夹中创建了此数据块-您可以执行以下操作 const upload = multer({ dest: `${__dirname}/uploads/images` }); app.post( "/api/users/:id/uploadProfilePic", upload.single("image"), updateProfilePic ); const updateProfileP

在我的express应用程序中,我有以下上载图像的代码-这似乎成功上载了图像,但它也在我的上载文件夹中创建了此数据块-

您可以执行以下操作

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上传的,然后你将它复制到了相同的路径。屏幕截图是从代码执行完毕并返回代码200时开始的。你能注释掉处理程序中的所有代码吗,如果我这样做,它只上传blob,而不是图像-我想要相反的你的问题有点误导,在这种情况下“这似乎成功上传了图像,但它也在我的上传文件夹中创建了这个数据blob——”
const storage = multer.diskStorage({
    destination: function (req, file, cb) {
      cb(null, 'uploads/')
    },
    filename: function (req, file, cb) {
      cb(null, file.originalname)
    }
  })

  const upload = multer({storage: storage})