0

My headers are set in constructor as follow:

this.headers = new Headers();
this.headers.append('Content-Type', 'multipart/form-data;boundary=--boundary');

I have collected data to post it out in formData

            .....
 let data = new FormData();
     data.append('file', file);
     data.append('fileName', file.name);
     data.append('fileSize', file.size.toString());
     data.append('fileType', file.type);
     data.append('fileLastMod', file.lastModifiedDate);
            .....

Here i am posting the data

let url = 'http://api.********.com/gallery/'+ this.selectedCategory;
            this._http.post(url, data, {headers : this.headers})
                .toPromise()
                .catch(reason => {
                    console.log(JSON.stringify(reason));
                }).then(result => {
                console.log('From Promise:', result);
            });

But i get following error:

enter image description here

API that i am approaching requires following:

enter image description here


So my question is how to set up these requirements like boundaries, content disposition an so on ? These are pretty new things to me.

2
  • change the header headers.set('Accept', 'application/json'); Commented Dec 28, 2017 at 16:29
  • nothing changed Commented Dec 28, 2017 at 16:36

1 Answer 1

4

If you are sending formdata object in request then do not need to import content-type.

Angular HTTP method support multipart type, where as HttpClient also support multipart with default reportProgress feature which will notify uploading status

Solution- Use HTTP method, it will set boundaries on its own.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.