javascript 文件名.path返回未定义的

aydmsdu9  于 2022-11-20  发布在  Java
关注(0)|答案(2)|浏览(129)

文件未保存在服务器上。path属性返回undefined。

const uploadProfile = (req, res) => {
  const form = formidable.IncomingForm();

  form.uploadDir = `./images`;
  form.keepExtensions = true;
  form.parse(req, (err, fields, files) => {
    if (err) {
      return res.json("Formidable cannot parse the form");
    }

    console.log(files.image.path);
   res.json(files.image.path);
  });
};
wi3ka0sx

wi3ka0sx1#

const uploadProfile = (req, res) => {

    const options = {
    uploadDir: `./images`,
    keepExtensions: true,
  };

  const form = new formidable.IncomingForm(options);

  form.parse(req, (err, fields, files) => {
    if (err) {
      return res.json("Formidable cannot parse the form");
    }

    const {filepath, originalFilename, newFilename, size , mimetype} = files.image
    //'image' is the fileName... files.fileName 
    console.log(newFilename, "...");
   
    res.json(newFilename);
  });
};

阅读有关从V1迁移到V2或V3的信息

zwghvu4y

zwghvu4y2#

请尝试::文件.图像.原始文件名

相关问题