NativeScript / nativescript-background-http

Background Upload plugin for the NativeScript framework
Apache License 2.0
102 stars 50 forks source link

IOS crashes after trying to upload an audio file. #228

Closed JCFowler closed 5 years ago

JCFowler commented 5 years ago

Make sure to check the demo app(s) for sample usage

Using the sample.

Make sure to check the existing issues in this repository

Doesn't look like theres any issues like this.

If the demo apps cannot help and there is no issue for your problem, tell us about it

Please, ensure your title is less than 63 characters long and starts with a capital letter.

Which platform(s) does your issue occur on?

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

tns - 5.4.0

{ "tns-android": { "version": "5.4.0" }, "tns-ios": { "version": "5.4.0" } "private": true, "dependencies": { "@angular/animations": "^7.2.15", "@angular/common": "^7.2.15", "@angular/compiler": "^7.2.15", "@angular/core": "^7.2.15", "@angular/forms": "^7.2.15", "@angular/http": "^7.2.15", "@angular/platform-browser": "^7.2.15", "@angular/platform-browser-dynamic": "^7.2.15", "@angular/router": "^7.2.15", "@fortawesome/angular-fontawesome": "^0.3.0", "@fortawesome/fontawesome-svg-core": "^1.2.18", "@fortawesome/free-solid-svg-icons": "^5.8.2", "@ngx-translate/core": "^11.0.1", "@ngx-translate/http-loader": "^4.0.0", "@ngxs-labs/emitter": "^1.9.0", "@ngxs/store": "^3.4.3", "ajv": "^6.10.0", "bootstrap": "^4.3.1", "core-js": "^2.6.8", "jquery": "^3.4.1", "nativescript-angular": "^7.2.4", "nativescript-audio": "^5.0.2", "nativescript-background-http": "^3.4.1", "nativescript-loading-indicator": "^2.5.2", "nativescript-secure-storage": "^2.4.0", "nativescript-theme-core": "^1.0.6", "nativescript-ui-dataform": "^4.0.0", "nativescript-ui-listview": "^6.3.0", "nativescript-ui-sidedrawer": "^6.0.0", "popper.js": "^1.15.0", "reflect-metadata": "~0.1.12", "rxjs": "~6.4.0", "tns-core-modules": "^5.4.1", "zone.js": "^0.8.26" }, "devDependencies": { "@angular-devkit/build-angular": "^0.13.9", "@angular/cli": "^7.3.9", "@angular/compiler-cli": "^7.2.15", "@nativescript/schematics": "~0.4.0", "@types/jasmine": "2.8.6", "@types/jasminewd2": "~2.0.3", "@types/node": "~8.9.4", "codelyzer": "^5.0.1", "jasmine-core": "~2.99.1", "jasmine-spec-reporter": "~4.2.1", "karma": "^4.1.0", "karma-chrome-launcher": "~2.2.0", "karma-coverage-istanbul-reporter": "~2.0.0", "karma-jasmine": "~1.1.1", "karma-jasmine-html-reporter": "^0.2.2", "nativescript-dev-sass": "~1.6.0", "nativescript-dev-typescript": "~0.8.0", "nativescript-dev-webpack": "^0.20.3", "protractor": "^6.0.0", "tns-platform-declarations": "^5.4.2", "ts-node": "~5.0.1", "tslint": "~5.9.1", "typescript": "~3.1.1" } }

Please, tell us how to recreate the issue in as much detail as possible.

Using nativescript-audio to create a recording. I am trying to send that recording as a multipart http request. The Android side is working perfectly, but iOS side crashes as soon as I try to do: this.session.multipartUpload(params, request);

Looking through the NPM package to the exact place it is crashing, its crashing at var newTask = this._session.uploadTaskWithRequestFromFile(request, fileURL); is in the background-http.ios.ts file.

The strange part is, nothing is being logged and as soon as I try to send the multipart request the app freezes for about 2 seconds and then just crashes.

Am I missing something on the configuration side of iOS?

Is there any code involved?

`this.session = bgHttp.session("checkin-upload");

    const request = {
        url: `${this.config.apiEndpoint}Submit/submitAction?action=1 `,
        method: "POST",
        headers: {
            Authorization: `Basic ${token}`,
            "Content-Disposition": "form-data; name=\"body\"",
            "Content-Type": "application/json",
            "File-Name": "recording.mp4"
        },
        // description: 'Testing',
    };

    let file = this.getAudioPath()
    let task: bgHttp.Task;
    let lastEvent = "";
    console.log('a', file)

    const params = [
        { name: "body", value: JSON.stringify(submitRequest) },
        { name: "fileToUpload", filename: file, mimeType: 'audio/mp4' }
    ];
    task = this.session.multipartUpload(params, request);`

Thank you

elena-p commented 5 years ago

Hi @JCFowler,

It seems like you are experiencing this issue: https://github.com/NativeScript/nativescript-background-http/issues/191#issuecomment-448308267 Can you confirm?

JCFowler commented 5 years ago

Hello @elena-p

Nope that wasn't the issue, after about an entire day of trying to figure out the issue, I finally just got it about 5 minutes ago.

The Url had an extra space at the end, and so the Android side is smart enough to deal with it, while the iOS side will crash.

So if, somehow, someone is dumb like me and added an extra space at the end of your URL, delete it so you don't waste a day like I did.

Thank you