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

Complete event doesn't fire on Android #26

Closed
3rror404 opened this issue Oct 10, 2016 · 8 comments
Closed

Complete event doesn't fire on Android #26

3rror404 opened this issue Oct 10, 2016 · 8 comments
Labels

Comments

@3rror404
Copy link

3rror404 commented Oct 10, 2016

Using the following example, the task complete event never fires.

function uploadImage(filePath) {
    var request = {
        url: "http://httpbin.org/post",
        method: "POST",
        headers: {
            "Content-Type": "application/octet-stream",
            "File-Name": "Test.png"
        },
        description: "{ 'uploading': " + "Test.png" + " }"
    };

    var task = session.uploadFile(filePath, request);
    task.on("progress", logEvent);
    task.on("error", logEvent);
    task.on("complete", uploadComplete);

    function logEvent(e) {
        console.log("----------------");
        console.log('Status: ' + e.eventName);
        if (e.totalBytes !== undefined) {
            console.log('current bytes transfered: ' + e.currentBytes);
            console.log('Total bytes to transfer: ' + e.totalBytes);
        }
    }

    function uploadComplete() {
        console.log('Upload complete');
    }
}

I see some progress updates in the console and I receive a local notification but the uploadComplete function is never called.

JS: onProgress
JS: ----------------
JS: Status: progress
JS: current bytes transfered: 4096
JS: Total bytes to transfer: 2700129
JS: onProgress
JS: ----------------
JS: Status: progress
JS: current bytes transfered: 720896
JS: Total bytes to transfer: 2700129
JS: onProgress
JS: ----------------
JS: Status: progress
JS: current bytes transfered: 1376256
JS: Total bytes to transfer: 2700129
JS: onProgress
JS: ----------------
JS: Status: progress
JS: current bytes transfered: 1769472
JS: Total bytes to transfer: 2700129
JS: onProgress
JS: ----------------
JS: Status: progress
JS: current bytes transfered: 2555904
JS: Total bytes to transfer: 2700129

The same code works fine on iOS.

┌──────────────────┬───────────────────────┬────────────────┬─────────────┐
│ Component        │ Current version       │ Latest version │ Information │
│ nativescript     │ 2.3.0                 │ 2.3.0          │ Up to date  │
│ tns-core-modules │ 2.4.0-2016-10-07-4335 │ 2.3.0          │ Up to date  │
│ tns-android      │ 2.3.0                 │ 2.3.0          │ Up to date  │
│ tns-ios          │ 2.3.0                 │ 2.3.0          │ Up to date  │
└──────────────────┴───────────────────────┴────────────────┴─────────────┘
@tsonevn tsonevn self-assigned this Oct 12, 2016
@tsonevn tsonevn added the bug label Oct 12, 2016
@tsonevn
Copy link
Contributor

tsonevn commented Oct 12, 2016

Hi @3rror404,
I reviewed your issue and found that this problem could be reproduced, when you try to upload image with large size. We will research, what is causing this problem for Android. Regarding to that I am attaching link to a sample project, where the problem could be reproduced.

@nraboy
Copy link

nraboy commented Apr 4, 2017

Was this ever fixed? I'm still having the same problem on Android.

@tsonevn
Copy link
Contributor

tsonevn commented Apr 5, 2017

Hi @nraboy,
I have to confirm that this is still a real issue. We will research the reason for this problem and will verify, whether this is something related to android-upload-service. Unfortunately, I cannot commit to an exact time frame when this will be ready.

@Daxito
Copy link
Contributor

Daxito commented Apr 5, 2017

This plugin is working for me very well, firing the Complete Event, uploading images 7 to 8 MB size, is this issue related to bigger files only???

@nraboy
Copy link

nraboy commented Apr 5, 2017

To be clear, it is uploading fine for me, however, the complete event is not firing for me. This is the case for uploads of any size, big or small. It isn't particularly useful if I don't know the upload has finished.

I have been testing on Android 6.0 if that makes a difference.

Best,

@RyanSMurphy
Copy link

+1, android only fires the error event for myself.

@PanayotCankov PanayotCankov mentioned this issue Jul 21, 2017
3 tasks
@lini
Copy link
Contributor

lini commented Dec 13, 2017

Please see #89 for more information about this issue. It seems the problem is with the https://httpbin/post test service itself. The response it sends back is too large when you upload large files and it cannot be handled correctly. If you test with another service that just responds with "File uploaded OK" or something similar, the complete event should fire as expected.

@lini lini closed this as completed Dec 13, 2017
@flow96
Copy link

flow96 commented Jun 22, 2018

Hi, I had the same error that the complete event was not triggered.
I was able to fix it by setting the statusCode to 200 in my server, as soon as the file has successfully been uploaded.

For example:

app.post("/upload", function(req, res){
    // .. Upload stuff and file saving
    // as soon as the file is uploaded
    res.statusCode = 200;
    res.setHeader('Content-Type', 'text/plain');
    res.end('OK\n');
});

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

No branches or pull requests

7 participants