将图像从e2e/assets/image.png
上载到REST API。
我有以下代码:
const documentUploadUrl = 'rest-api-url';
const headers = new HttpHeaders({'Content-Type': 'multipart/form-data',Authorization: 'auth'});
const fileToUpload = '../../assets/image.png';
const filePath = path.resolve(__dirname, fileToUpload);
const formData: FormData = new FormData();
formData.append('file', filePath, '1.png');
http.post(documentUploadUrl, formData, {headers: headers})
.subscribe((value1) => {
console.log(value1);
},
error => {
console.log(error);
});
我得到了错误:
未定义FormData