HttpErrorResponse {headers: HttpHeaders, status: 401, statusText: «Unauthorized» - отправка изображения с помощью почтового запроса - PullRequest
1 голос
/ 21 октября 2019

Я отправляю файл с почтовым запросом, получаю - «Несанкционированный» 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, status: 401, statusText: "Unauthorized"

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...