我正在发送带有后期处理请求的文件,并且越来越-“未经授权” upload.component.html。和upload.component.ts代码-
<input id="file-input" type="file" (change)="fileChange($event)" accept="image/*" capture="environment" />
httpOptions = {
headers: new HttpHeaders({
'Content-Type': '',
'Authorization': localStorage.getItem('access_token')
})
}
constructor(public http: HttpClient) {}
results:any;
fileChange(event) {
const fileList: FileList = event.target.files;
if (fileList) {
const file = fileList[0];
const formData = new FormData();
formData.append('Policy_files', file, file.name);
this.http.post(SERVER_URL, formData, this.httpOptions).subscribe(
response => {
console.log(response)
} , (error) => {
if(error){
alert('Server Responded With An Error')
console.log(error)
}}
);
}
}
更新-HttpErrorResponse {headers:HttpHeaders,状态:401,statusText:“未经授权”