[英]How to sen file using httpClient in Angular?
我尝试使用HttpClient
发送文件:
public async uploadProfile(data: UploadProfile): Promise<any> {
return await this.http.post(this.uploadProfileUrl, data).toPromise();
}
在发送文件之前,我将其准备为二进制数组:
interface UploadProfile {
file: any;
}
file = [123, 10, 32, 32, 34, 100, 105, 115, 97, 98, 108, 101, 83, 105, 122, 101, 76, 105, 109]
但我得到错误:
TypeError: Cannot read property 'toLowerCase' of undefined
at HttpXsrfInterceptor.intercept (http.js:2177)
这可能是由于您的请求期间未定义的 url。 尝试执行以下操作作为测试:
改变:
public async uploadProfile(data: UploadProfile): Promise<any> {
return await this.http.post(this.uploadProfileUrl, data).toPromise();
}
到:
public async uploadProfile(data: UploadProfile): Promise<any> {
return await this.http.post('http://yourUrl/resource', data).toPromise();
}
如果这有效并且您不再看到错误,请尝试找出在您拨打电话时未定义uploadProfileUrl
原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.