# POST multipart/form-data in Ionic Native HTTP

**URL:** <https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305>\
**Category:** Ionic Native\
**Created:** [January 5, 2018, 8:00am UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305 "2018-01-05T08:00:38Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kanishk12](https://avatars.discourse-cdn.com/v4/letter/k/c4cdca/32.png) [@Kanishk12](https://forum.ionicframework.com/u/Kanishk12)\
**Post date:** [January 5, 2018, 8:00am UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/1 "2018-01-05T08:00:39Z")

</div>

Hi All

Is there a way to do POST request with multipart/form-data in ionic native HTTP ?

---

<div class="post-metadata">

**Author:** ![vd\_virani](https://avatars.discourse-cdn.com/v4/letter/v/57b2e6/32.png) [@vd\_virani](https://forum.ionicframework.com/u/vd_virani)\
**Post date:** [January 5, 2018, 8:12am UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/2 "2018-01-05T08:12:25Z")

</div>

@Kanishk12

try below example

[https://devdactic.com/ionic-2-images/](https://devdactic.com/ionic-2-images/)

thanks

---

<div class="post-metadata">

**Author:** ![Kanishk12](https://avatars.discourse-cdn.com/v4/letter/k/c4cdca/32.png) [@Kanishk12](https://forum.ionicframework.com/u/Kanishk12)\
**Post date:** [January 5, 2018, 8:41am UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/3 "2018-01-05T08:41:13Z")

</div>

@vd_virani, Thanks for replying.

It is a great example, but to use this i’ll have to change a whole lot of my code. Below are some lines from my code, just see if you can suggest something in this approach:

let **clientConfirmData** = new FormData();  
var blob = new Blob([this.signature], { type: ‘image/png’ });

**clientConfirmData**.append(“patientConfirmation”, blob);

this.http.post(url, **clientConfirmData** , headers)  
.then(data =\>{

```
                                        })
                                        .catch(error => {
                                          
                                        }));

```

so, my question is does **clientConfirmData** has to be a JSON object for it to work, won’t it work with FormData type object ? ( http is from ionic native’s not angular’s)

Thanks

---

<div class="post-metadata">

**Author:** ![stuccosalt](https://avatars.discourse-cdn.com/v4/letter/s/d9b06d/32.png) [@stuccosalt](https://forum.ionicframework.com/u/stuccosalt)\
**Post date:** [May 7, 2018, 11:33pm UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/4 "2018-05-07T23:33:08Z")

</div>

Did you ever solve this? I need to send as multipart/form-data as required by the server

---

<div class="post-metadata">

**Author:** ![Kanishk12](https://avatars.discourse-cdn.com/v4/letter/k/c4cdca/32.png) [@Kanishk12](https://forum.ionicframework.com/u/Kanishk12)\
**Post date:** [May 9, 2018, 4:24am UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/5 "2018-05-09T04:24:15Z")

</div>

No, Ionic’s Native Http does not support FormData type objects, But you can use Angular’s Http to achieve the same.  
In my case, the backend guys had to change the service to accept JSON Object instead of FormData Object.

---

<div class="post-metadata">

**Author:** ![hjchin](https://avatars.discourse-cdn.com/v4/letter/h/db5fbb/32.png) [@hjchin](https://forum.ionicframework.com/u/hjchin)\
**Post date:** [May 31, 2018, 2:43pm UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/6 "2018-05-31T14:43:29Z")

</div>

Ionic does support FormData. To those who are looking for answer, following codes work

```auto
postFile(token:string, file:Blob){

        let url = WebService.API_POST_FILE + "?token="+token;
        let httpOptions = {
            headers: new HttpHeaders({
                'enctype': 'multipart/form-data; boundary=----WebKitFormBoundaryuL67FWkv1CA'
            })
        };
        
        let formData = new FormData();
        formData.append('file', file, 'test.jpg');

        console.log("post photo to URL at "+url);
        return this.http
            .post<SimpleResponse>(
                url,
                formData,
                httpOptions
        );
    }

```

---

<div class="post-metadata">

**Author:** ![murwa](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/murwa/32/120412_2.png) [@murwa](https://forum.ionicframework.com/u/murwa)\
**Post date:** [December 9, 2018, 3:19pm UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/7 "2018-12-09T15:19:39Z")

</div>

Hey, this is angular’s http service. The question is for Ionic Native HTTP

---

<div class="post-metadata">

**Author:** ![mfouash](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mfouash/32/112535_2.png) [@mfouash](https://forum.ionicframework.com/u/mfouash)\
**Post date:** [February 19, 2019, 9:02am UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/8 "2019-02-19T09:02:41Z")

</div>

any help please face same issue can’t send selected file to my http post api end point ☹

---

<div class="post-metadata">

**Author:** ![SrinivasK](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/srinivask/32/124455_2.png) [@SrinivasK](https://forum.ionicframework.com/u/SrinivasK)\
**Post date:** [February 21, 2019, 5:26am UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/9 "2019-02-21T05:26:27Z")

</div>

Hi,  
Ionic native HTTP request accepts only, object and array formats with key value pairs are the string format.  
we can pass file as a base64 string format.  
in backend decode the base64 string.

---

<div class="post-metadata">

**Author:** ![baotpham](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/baotpham/32/122890_2.png) [@baotpham](https://forum.ionicframework.com/u/baotpham)\
**Post date:** [May 11, 2019, 12:55am UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/10 "2019-05-11T00:55:09Z")

</div>

For those who are looking for to upload images using Ionic Native HTTP. There is function called `uploadFile()` that you can use.

> **[silkimen/cordova-plugin-advanced-http](https://github.com/silkimen/cordova-plugin-advanced-http#uploadFile)**
>
> Cordova / Phonegap plugin for communicating with HTTP servers. Allows for SSL pinning! - silkimen/cordova-plugin-advanced-http

---

<div class="post-metadata">

**Author:** ![ioclaudio](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ioclaudio/32/126373_2.png) [@ioclaudio](https://forum.ionicframework.com/u/ioclaudio)\
**Post date:** [May 31, 2019, 10:26am UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/11 "2019-05-31T10:26:35Z")

</div>

> [@hjchin](#):
>
> FormData

Hi,  
I’m using this code to send data:

```auto
    const headers = {
      'enctype': 'multipart/form-data; boundary=WebAppBoundary',
      'Content-Type': 'multipart/form-data; boundary=WebAppBoundary',
      'auth': tempToken
    };

    const formData = new FormData();
    const dataJson = {
      'deviceId': 77,
      'description': 'gino',
      'warningTypeId': 7
    };
    const jsonString = JSON.stringify(dataJson);
    formData.append('data', jsonString);

    return this.httpClient.post(commandUrl,
      formData,
      {headers: headers, responseType: responseType});

```

But on the server I can see that the body of the request is empty.  
That is the text into the “data” variable doesn’t arrive to the server.  
Which could be the problem?  
The web service is pre-existent and working.

Thank you.

cld

---

<div class="post-metadata">

**Author:** ![ioclaudio](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ioclaudio/32/126373_2.png) [@ioclaudio](https://forum.ionicframework.com/u/ioclaudio)\
**Post date:** [May 31, 2019, 10:37am UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/12 "2019-05-31T10:37:18Z")

</div>

Excuse me,  
the problem was the header, this is the right one:

```auto
    const headers = {
      'enctype': 'multipart/form-data;',
      'Accept': 'plain/text',
      'Access-Control-Allow-Origin': '*',
      'Access-Control-Allow-Methods': 'POST, GET, OPTIONS, PUT',
      'Access-Control-Allow-Headers': 'Authorization, Origin, Content-Type, X-CSRF-Token',
      'auth': tempToken
    };

```

---

<div class="post-metadata">

**Author:** ![ankant](https://avatars.discourse-cdn.com/v4/letter/a/e99b99/32.png) [@ankant](https://forum.ionicframework.com/u/ankant)\
**Post date:** [July 5, 2019, 11:02am UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/13 "2019-07-05T11:02:23Z")

</div>

I am not able to establish connection using HttpClient or any other api except native http that doesnot support form data. How can I use other api and establish successful connection? Here is my code and details Ionic native http post formdata  
I have tried every solution I could find but to no result.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 9:56pm UTC](https://forum.ionicframework.com/t/post-multipart-form-data-in-ionic-native-http/117305/14 "2021-07-19T21:56:22Z")

</div>

Closed on July 19, 2021, 9:56pm UTC


