将图像从e2e / assets文件夹上传到Rest API端点

时间:2019-09-05 09:29:31

标签: angular protractor

将图像从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

0 个答案:

没有答案