plugins icon indicating copy to clipboard operation
plugins copied to clipboard

[@nativescript/background-http] upload error responseCode = -1

Open ghost opened this issue 5 years ago • 1 comments

Please, provide the following version numbers that your issue occurs with:

CLI: 7.0.10 "@nativescript/android": "7.0.1", "@nativescript/ios": "7.0.5",

angular 10.2.1

When I upload a file, I get the error below.

e.responseCode = -1

this is my code

public _uploadBinary(fileName: string) {
    this.file = fileName;
    const name = this.file.substr(this.file.lastIndexOf('/') + 1);
    const description = `${name}`;

    const request = {
        url: this.avatarUrl,
        method: 'POST',
        headers: {
            "Content-Type": "application/octet-stream",
            "File-Name": name,
            "Authorization": `Bearer ${this.authTokenService.token}`
        },
        description: description,
        androidAutoDeleteAfterUpload: true,
        androidNotificationTitle: 'NativeScript HTTP background',
    };

    let task: Task;

    var params = [{name: name, value: "value"}, {name:"fileToUpload", filename: this.file, mimeType: 'image/jpeg'}];
    task = this.session.multipartUpload(params, request);
    task.on("progress", (e) => {
        console.log("upload progress", JSON.stringify(e));
    });
    task.on("error", (e) => {
        console.log("upload error", JSON.stringify(e));
        alert("error received " + e.responseCode + " code.");
    });
    task.on("responded", (e) => {
        console.log("responded", JSON.stringify(e) );
        console.log("responded data", JSON.stringify(e.data) );
    });
    task.on("complete", (e) => {
        console.log("upload complete", JSON.stringify(e));
    });

    this.tasks.push(task);
}

ghost avatar Nov 25 '20 17:11 ghost

@pedicini did you found any solution for this problem ?

Geoffsdev avatar May 21 '21 18:05 Geoffsdev