NativeScript / NativeScript/plugins

[@nativescript/background-http] error Context.startForegroundService() did not then call Service.startForeground()

Offen
#63 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
TypeScript
Sterne
206
Forks
123
Ø Merge
2 T. 1 Std.
Gemergte PRs (30 T.)
1

Beschreibung

Hello,
We are using @nativescript/background-http on NativeScript with Angular to upload photos, web API .net Core 3.1

We have this error

System.err: An uncaught Exception occurred on "main" thread.
System.err: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{6fabfc7 u0 it.openweb.next2u/net.gotev.uploadservice.UploadService}
System.err:
System.err: StackTrace:
System.err: android.app.RemoteServiceException: Context.startForegroundService() did not then call Service.startForeground(): ServiceRecord{6fabfc7 u0 it.openweb.next2u/net.gotev.uploadservice.UploadService}
System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2052)
System.err: at android.os.Handler.dispatchMessage(Handler.java:107)
System.err: at android.os.Looper.loop(Looper.java:214)
System.err: at android.app.ActivityThread.main(ActivityThread.java:7710)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:516)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)

Version numbers:
-CLI 7.1.1
"@nativescript/android": "7.0.1",
"@nativescript/ios": "7.1.0",

"@nativescript/background-http": "^5.0.1",

package.json:

"dependencies": {
"@angular/animations": "~11.0.5",
"@angular/common": "~11.0.5",
"@angular/compiler": "~11.0.5",
"@angular/core": "~11.0.5",
"@angular/forms": "~11.0.5",
"@angular/platform-browser": "~11.0.5",
"@angular/platform-browser-dynamic": "~11.0.5",
"@angular/router": "~11.0.5",
"@nativescript/angular": "~11.0.0",
"@nativescript/background-http": "^5.0.1",
"@nativescript/core": "^7.1.0",
"@nativescript/theme": "~3.0.1",
"@nativescript/types": "^7.1.0",
"@nativescript/webpack": "^4.0.0",
"jwt-decode": "^2.2.0",
"nativescript-ui-sidedrawer": "~9.0.3",
"reflect-metadata": "~0.1.13",
"rxjs": "~6.6.3",
"zone.js": "~0.11.3"
},
"devDependencies": {
"@angular/compiler-cli": "~11.0.5",
"@nativescript/android": "7.0.1",
"@nativescript/ios": "7.1.0",
"@ngtools/webpack": "~11.0.5",
"codelyzer": "~6.0.0",
"node-sass": "^4.14.1",
"tslint": "~6.1.3",
"typescript": "~4.0.0"
}

UploadFile.ts

public _uploadFile() {

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

    const request = {
        url: `${this.avatarUrl}`,
        method: 'POST',
        utf8: true,
        headers: {
            "Content-Type": "multipart/form-data",
            "File-Name": name
        },
        description: description,
        androidAutoDeleteAfterUpload: false,
        androidNotificationTitle: 'Uploading Product Image',
        androidDisplayNotificationProgress:true
    };

    let task: Task;
    let lastEvent = '';

    const params = [
        { name: 'test', value: 'value' },
        { name: 'testInt', value: 10 },
        { name: 'bool', value: true },
        { name: 'fileToUpload', filename: this.file, mimeType: 'image/jpeg' },
    ];

    task = this.session.multipartUpload(params, request);

    function onEvent(e) {
        if (lastEvent !== e.eventName) {
            // suppress all repeating progress events and only show the first one
            lastEvent = e.eventName;
        } else {
            return;
        }

        this.events.push({
            eventTitle: e.eventName + ' ' + e.object.description,
            eventData: JSON.stringify({
                error: e.error ? e.error.toString() : e.error,
                currentBytes: e.currentBytes,
                totalBytes: e.totalBytes,
                body: e.data,
                responseCode: e.responseCode,
            }),
        });
    }

    task.on('progress', onEvent.bind(this));
    task.on('error', onEvent.bind(this));
    task.on('responded', onEvent.bind(this));
    task.on('complete', onEvent.bind(this));
    lastEvent = '';
    this.tasks.push(task);
}

web API .net Core 3

    [HttpPost("attachement")]
    public async Task<ActionResult> UploadAttachement([FromForm] IFormFile file)
    {
        var attachement = new modelProfile
        {
            ContentType = file.ContentType,
            name = file.FileName
        };
        using (var stream = file.OpenReadStream())
        {
            attachement.content = new byte[file.Length];
            await stream.ReadAsync(attachement.content, 0, (int)file.Length);
        };

        await serviceUpload.uploadProfile(attachement);

        return Ok();
    }

Can you please help with this error and the way to fix it?
Thank you

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit UploadFile.ts und dem Aufruf session.multipartUpload und verfolge dann den im Stacktrace genannten Android UploadService. Reproduziere den Upload mit den aufgeführten NativeScript- und Plugin-Versionen und ermittle, wo der Lebenszyklus des Foreground-Service fehlschlägt; abgeschlossen ist die Aufgabe, wenn der Upload keine RemoteServiceException mehr auslöst.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
android, angular, typescript
Bereich
mobile
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.