question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

onCompleted is not called

See original GitHub issue
  • Android Upload Service version (e.g. 3.0.3):
  • Android version and API version (e.g. 6.0.1 API 23):

I expect the onCompleted callback to be called when the upload is finished But it’s not called

This is my request code:

final String uploadId =
             new net.gotev.uploadservice.MultipartUploadRequest(getApplicationContext(), "https://www.motolife.bg/post_avatar.php")
             .addFileToUpload(filename, "photo")
             .addParameter("parameter","value")
             .setDelegate(new net.gotev.uploadservice.UploadStatusDelegate() {
               @Override
               public void onProgress(net.gotev.uploadservice.UploadInfo uploadInfo) {
                 Log.e("gotev","onProgress eltstr="+uploadInfo.getElapsedTimeString()+" elt="+uploadInfo.getElapsedTime()+" ratestr="+
                 uploadInfo.getUploadRateString()+" prc="+uploadInfo.getProgressPercent()+" tb="+uploadInfo.getTotalBytes()+" ub="+uploadInfo.getUploadedBytes());
               }
               @Override
               public void onError(net.gotev.uploadservice.UploadInfo uploadInfo, Exception e) {
                 Log.e("gotev","onError "+e.getMessage() + e.getStackTrace());
               }
               @Override
               public void onCompleted(net.gotev.uploadservice.UploadInfo uploadInfo, net.gotev.uploadservice.ServerResponse serverResponse) {
                 Log.e("gotev","onCompleted "+serverResponse.getHttpCode()+" "+serverResponse.getBodyAsString());
               }
               @Override
               public void onCancelled(net.gotev.uploadservice.UploadInfo uploadInfo) {
                 Log.e("gotev","onCancelled "+uploadInfo);
               }
             }).startUpload();

This is my library initialization code

net.gotev.uploadservice.UploadService.NAMESPACE = bg.motolife.app.BuildConfig.APPLICATION_ID;

And this is my logcat output

08-19 19:31:21.649 1706-1706/bg.motolife.app E/gotev: uploadId=7e9235a9-de5a-4ead-8e2f-93ca25f30b20
08-19 19:31:21.938 1706-1706/bg.motolife.app E/gotev: onProgress eltstr=0s elt=248 ratestr=0 bit/s prc=0 tb=174870 ub=103
                                                      {"st":0}

The request is successfully received by the server. But there is now output from the onCompleted callback

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
gotevcommented, Aug 20, 2016

Updated the Monitoring upload status wiki page:

The recommended way to use delegates inside Activities or Services is to implement the UploadStatusDelegate interface in your Activities or Services instead of using the anonymous inner class, to prevent variable out of scope problems.

Please make use of markdown syntax to improve readability the next time, as I’ve noted in the asking for help wiki page. I’ve done that for you this time in your posts.

Made some tests using the node.js demo server and the demo app provided in the examples, and this is what I get in the LogCat:

I/UploadServiceDemo: ID 27a37309-dde3-47cf-8f89-cc223d4fb767: completed in 0s at 0,00 Kbit/s. Response code: 200, body:[Upload Ok!]
E/UploadServiceDemo: Success:/storage/emulated/0/Download/11700901_10204551472013917_5124724800122680120_o.jpg
I/Header: Connection: close
I/Header: Date: Sat, 20 Aug 2016 09:48:04 GMT
I/Header: transfer-encoding: 
I/Header: X-Android-Received-Millis: 1471686484540
I/Header: X-Android-Response-Source: NETWORK 200
I/Header: X-Android-Selected-Protocol: http/1.1
I/Header: X-Android-Sent-Millis: 1471686484410
I/Header: X-Powered-By: Express
E/UploadServiceDemo: Printing response body bytes
E/UploadServiceDemo: 55 
E/UploadServiceDemo: 70 
E/UploadServiceDemo: 6C 
E/UploadServiceDemo: 6F 
E/UploadServiceDemo: 61 
E/UploadServiceDemo: 64 
E/UploadServiceDemo: 20 
E/UploadServiceDemo: 4F 
E/UploadServiceDemo: 6B 
E/UploadServiceDemo: 21 

So those CR and LF characters are added by your PHP server-side script in the response. Here you can see the code which is being executed in the onCompleted method. If you dump network traffic I’m pretty sure you will see CR and LF at the beginning of the response body coming from your server.

0reactions
andshcommented, Aug 20, 2016

To ensure the server response encoding I’ve modified the PHP script the following way: header(‘Content-Type: application/json; charset=utf-8’); echo utf8_encode(json_encode(array(“st”=>0)));

On the client side in the onCompleted method I inserted the following code int code = serverResponse.getHttpCode(); Log.e(“gotev”, “onCompleted3 " + code); byte[] ba = serverResponse.getBody(); for (int j=0; j<ba.length; j++) { Log.e(“byte”,String.format(”%02X ", ba[j])); } String str2 = new String(ba, Charset.forName(“UTF8”)); Log.e(“gotev”, "strs equ= " + resps.equals(str2)); JSONObject jo = new JSONObject(resps); int st = jo.getInt(“st”); Log.e(“gotev”, “onCompleted5 st=” + st);

And I’ve got the following in the Logcat in my Android Studio 08-20 12:13:50.999 20111-20111/bg.motolife.app E/gotev: onCompleted3 200 {“st”:0} 08-20 12:13:51.000 20111-20111/bg.motolife.app E/byte: 0D 08-20 12:13:51.000 20111-20111/bg.motolife.app E/byte: 0A 08-20 12:13:51.000 20111-20111/bg.motolife.app E/byte: 7B 08-20 12:13:51.000 20111-20111/bg.motolife.app E/byte: 22 08-20 12:13:51.000 20111-20111/bg.motolife.app E/byte: 73 08-20 12:13:51.000 20111-20111/bg.motolife.app E/byte: 74 08-20 12:13:51.000 20111-20111/bg.motolife.app E/byte: 22 08-20 12:13:51.000 20111-20111/bg.motolife.app E/byte: 3A 08-20 12:13:51.000 20111-20111/bg.motolife.app E/byte: 30 08-20 12:13:51.000 20111-20111/bg.motolife.app E/byte: 7D 08-20 12:13:51.000 20111-20111/bg.motolife.app E/gotev: strs equ= true 08-20 12:13:51.001 20111-20111/bg.motolife.app E/gotev: onCompleted5 st=0

See, in the second string i don’t see any string header because of new line and carriage return characters in the string And then In the byte loop we see first 2 bytes are exactly line_feed and carriage_return

From where are these two bytes in the beginning of the serverResponse?

Read more comments on GitHub >

github_iconTop Results From Across the Web

onCompleted not called when useQuery refetch finished #3709
Im using Apollo 3.0.1 on a React Native project and I'm facing the same issues, useLazyQuery does not run onCompleted after I call...
Read more >
onCompleted callback is not calling for 2nd ... - Stack Overflow
It seems to be a known issue that Apollo's onCompleted option works differently between queries fulfilled over the network and by the cache....
Read more >
onCompleted option not available for refetchQueries - Help
I wanna execute a query on completion of a mutation [every time an action occurs/mutation is called]. now apollo provides an option to...
Read more >
Component.onCompleted doesn't seem to be called
onCompleted : console.log("This will not be printed") } ... plugin first and only then attaches the slots that handle the call to console.log....
Read more >
Solution: onCompleted - Thinkster.io
Solution: onCompleted ... Join our newsletter! Get exclusive content, resources, and more! Subscribe. 1-2 emails per week, no ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found