5

I know this type of question has asked several times in here and some forums.

What i'm trying to do is upload a file to my server. Down below is my first attempt to set headers to multipart/form-data. Below is my service for the file upload.

uploadNewFile (formData): Observable<any> {
    const headers = new HttpHeaders();
    headers.set('Content-Type', undefined);
    return this.http.post(environment.baseURL+'api/v1/company/someFileUpload' , formData, {headers: headers})
      .pipe(
        catchError(this.formatErrors)
      );
  }

But when i do this, i'm getting this error.

Error: Multipart: Boundary not found

But then after seeing this question(Send multipart/form-data files with angular using $http) i changed my header to this.

const headers = new HttpHeaders();
headers.set('Content-Type', undefined)

But when I changed it like that, I am getting this error.

enter image description here

But when i check an aswer for that error it says that i need to add a handler in here (Uncaught TypeError: Cannot read property 'ngOriginalError' of undefined at getOriginalError - when httpClient returned string)

But i have a handler for my service. Service is pasted in below.

uploadNewFile (formData): Observable<any> {
    const headers = new HttpHeaders();
    headers.set('Content-Type', undefined);
    return this.http.post(environment.baseURL+'someFileUpload' , formData, {headers: headers})
      .pipe(
        catchError(this.formatErrors)
      );
  }

How can i solve this?

Dushan
  • 1,365
  • 20
  • 26
  • 1
    I don't see you're passing the headers to the post. In the other hand I think you need to do this instead `headers = headers.set('Content-Type',
    );`
    – dcg Feb 04 '20 at 19:07
  • oh sorry, my bad. I have copied it without the header part. I tried to upload without hears too. But it didn't work either. – Dushan Feb 04 '20 at 19:32

1 Answers1

5

Check for interceptors, because you may have set cintent type for application json in the interceptors