使用angular8,nodejs和multer上传视频时出现意外字段

时间:2019-11-07 08:24:19

标签: node.js angular8 multer image-upload video-upload

我正在上传图像和视频,在上传图像时工作正常,但是在上传视频时出现“意外字段”错误 我已经提到我的源代码以供参考

请帮助我,谢谢!

 <input id="cctv_image1" name="cctv_image1" type="file" class="dropify"
                                    data-default-file="" data-show-errors="true"
                                    data-allowed-file-extensions="jpeg jpg png gif" formControlName="image"
                                    (change)="selectImage($event)">

 <input autocomplete="off" type="file" id="cctv_image3" name="cctv_image3" multiple
                                    type="file" accept=".mp4" class="dropify" data-default-file=""
                                    data-allowed-file-extensions="mp4" formControlName="video"
                                    (change)="selectVideo($event)">

selectImage(event) {
    this.image = event['target']['files'][0];
  }

  selectVideo(event) {
    this.video = event['target']['files'][0];
  }


const postData = new FormData();
 if (this.video) {
      console.log('video_found');
      postData.append('video', noticeData.video);
    }
postData.append('image', noticeData.image);

router.post('/create-notice', middleware.checkToken, multer({storage: image}).single('image'), multer({storage: video}).single('video'), complaintController.createNotice);

onst image = multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, "../src/assets/public/photo");
  },
  filename : (req, file, cb) => {
    const ext = MIME_TYPE_MAP[file.mimetype];
    cb(null, Date.now() + '.' + ext);
  }
});

const video = multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, "../src/assets/public/video");
  },
  filename : (req, file, cb) => {
    const ext = VIDEO_MIME_TYPE_MAP[file.mimetype];
    console.log(ext); return;
    cb(null, Date.now() + '.' + ext);
  }
});

1 个答案:

答案 0 :(得分:0)

从HTML的输入声明中删除“多个”,或者将“数组”添加到multer调用中。