【问题标题】:files.fileName.path returns undefined in formidablefiles.fileName.path 在强大中返回 undefined
【发布时间】:2022-01-13 09:13:56
【问题描述】:

文件未保存在服务器上。 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);
  });
};

【问题讨论】:

    标签: javascript express file formidable


    【解决方案1】:
    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-06
      • 2021-06-24
      • 1970-01-01
      相关资源
      最近更新 更多