NativeScript / NativeScript/plugins

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

Open
#43 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
206
Forks
123
Avg merge
2d 1h
Merged PRs (30d)
1

Description

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);
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the multipartUpload call in _uploadBinary with the reported NativeScript CLI, Android, iOS, and Angular versions, then inspect the background-http task error handling for responseCode -1. Compare Android and iOS behavior and determine whether the upload reaches the server; done means identifying the cause and documenting or correcting the error behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
android, angular, ios, typescript
Domain
mobile-dev, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.