silkimen / cordova-plugin-advanced-http

Cordova / Phonegap plugin for communicating with HTTP servers. Allows for SSL pinning!
MIT License
391 stars 313 forks source link

send file with multipart and formData stucks #487

Open asroboy opened 1 year ago

asroboy commented 1 year ago

request stucks when send file with serialize is 'multipart' and form data, not give any responds even after very long-long time here my example of use

  actionApiMultipart(link: string, body: any, heeader: any, filePaths: string | string[], nName: string | string[]) {
    console.log('request data : ');
    console.log(body);
    // this.http.setDataSerializer('multipart');
    return this.http.sendRequest('http://192.168.0.4/dpmdapps/api/' + link, {
      method: 'post',
      data: body,
      headers: heeader,
      serializer: 'multipart',
      filePath: filePaths,
      name: nName
    });
  }
GabrielVictorF commented 1 year ago

I had the same problem. The request response simply does not exist, as if it has remained in limbo. I tested using angular http and I didn't have the same problem.

FrancescoPaiola commented 1 year ago

Same problem here.

JosefBredereck commented 1 year ago

I have the same issue and was wondering if I did something wrong. I followed the instructions in the main readme and also https://github.com/silkimen/cordova-plugin-advanced-http/wiki/Web-APIs-required-for-Multipart-requests

Further I'm using capacitor and not Cordova, maybe this causes an issue?

Dragennia commented 11 months ago

I found the solution here : https://github.com/ionic-team/capacitor/issues/1564#issuecomment-538200971

In www/helpers.js I replaced:

var reader = new global.FileReader();

by:

const fileReader = new global.FileReader();
const zoneOriginalInstance = fileReader["__zone_symbol__originalInstance"];
var reader = zoneOriginalInstance || fileReader;

I hope it will work for you as well.

TiBz0u commented 6 months ago

Hi @silkimen , Is it possible to include this fix in the next version? It's atm blocking for using multipart into Capacitor project. Thanks Kr

wsomdev commented 6 months ago

For those that are not capable to fork the plugin and need to erase the fileReader at a higher level, here's a snippet code :

export class ZoneJSFileReader extends FileReader {
    set onload(cb: () => void) {
        const instanceZone = (this as any)?.["__zone_symbol__originalInstance"];

        if (instanceZone) {
            instanceZone.onload = cb;
        } else {
            super['onlaod'] = cb;
        }
    }

    public override readAsArrayBuffer(arrBuffer: Blob): void {
        const instanceZone = (this as any)?.["__zone_symbol__originalInstance"];

        if (instanceZone) {
            instanceZone.readAsArrayBuffer(arrBuffer);
        } else {
            super.readAsArrayBuffer(arrBuffer);
        }
    }
}

And just erase it before doing your post operation

window.FileReader = ZoneJSFileReader;