我正在尝试构建一个有角度的表单,我将在其中上传 2 张不同的照片。
我在 nodejs 上使用“ multer ”,在 angular中使用“ ng2-file-upload ”。
我需要为每张照片设置一个唯一标识符,以便能够正确处理它们。
multer设置为使用 html name 属性。问题是ng2-file-upload默认将输入类型 file -的属性名称更改为字符串file。
当我尝试运行此代码时:
节点.js:
const upload = multer({
storage
}).fields([
{ name: 'posterPic'},
{ name: 'widePic'}
]);
角度:
<div class="form-group">
<input type="file" id="posterPic" [name]="posterPic" ng2FileSelect [uploader]="uploader">
</div>
<div class="form-group">
<input type="file" id="widePic" [name]="widePic" ng2FileSelect [uploader]="uploader">
</div>
上传时 - 'ng2-file-upload' 将name="posterPic"
and更改name="widePic"
为name="file"
.
错误:
{ [Error: Unexpected field]
code: 'LIMIT_UNEXPECTED_FILE',
field: 'file',
storageErrors: [] }
任何人都知道如何更改ng2-file-upload默认行为以将文件输入的名称属性更改为“文件”?
非常感谢!
ps
告诉 multer 接受 any() 对我没有帮助。我需要能够识别这 2 个不同的输入。