Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send file with multipart and formData stucks #487

Open
asroboy opened this issue Nov 24, 2022 · 6 comments
Open

send file with multipart and formData stucks #487

asroboy opened this issue Nov 24, 2022 · 6 comments

Comments

@asroboy
Copy link

asroboy commented Nov 24, 2022

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
Copy link

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
Copy link

Same problem here.

@JosefBredereck
Copy link

JosefBredereck commented Apr 4, 2023

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
Copy link

Dragennia commented May 25, 2023

I found the solution here :
ionic-team/capacitor#1564 (comment)

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
Copy link

TiBz0u commented Oct 17, 2023

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
Copy link

wsomdev commented Oct 18, 2023

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants