capacitor-community / http

Community plugin for native HTTP
MIT License
208 stars 135 forks source link

Empty FormData on device #240

Open dhayanth-dharma opened 2 years ago

dhayanth-dharma commented 2 years ago

Describe the bug I'm using this http plugin in Vue 3 + Ionic 6. The formdata is being sent successfully when I test it on the browser. I am using the following headers:

'Content-Type': 'multipart/form-data; boundary=WebAppBoundary',
'enctype': 'multipart/form-data; boundary=WebAppBoundary'

But, empty data is sent when testing the app on the Android simulator. I have tried Http.uploadFile() too. But still, I get empty data to the server-side. I have File (Blob) object in the form data.

My code:

        const token = store.state.account.jwtToken;
        const uploadDefaultHeader = {'Authorization': token ? token : '',
        'Content-Type': 'multipart/form-data; boundary=WebAppBoundary',
        'enctype': 'multipart/form-data; boundary=WebAppBoundary'};

        const options = {
           url: `${baseUrl}${url}`,
           headers: uploadDefaultHeader,
           data: formData,
           params: params(param)
        };
        const response = await Http.post(options);

Expected behavior I want to send multipart/formdata to the API endpoint with this plugin.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Am I missing any options here? I could not find any related information in the document.

lnoir commented 2 years ago

@dhayanth-dharma I'm encountering the same issue. Did you find a solution or workaround?

dhayanth-dharma commented 2 years ago

@lnoir This is not resolved yet. You can follow the issue >> https://github.com/capacitor-community/http/issues/213

I started to use the following Cordova plugin >> https://www.npmjs.com/package/cordova-plugin-advanced-http and it works well with formData. Capacitor considers the Cordova plugin as an npm pack. You can use this plugin or Axios with a CORS proxy server.

lnoir commented 2 years ago

@dhayanth-dharma Yea I came across that plugin too, but I ended up just setting the server host parameter to a subdomain in the capacitor config.