tus / tus-android-client

The tus client for Android.
https://tus.io/
161 stars 46 forks source link

Additional unnecessary call if the file size is divisble by requestPayloadSize #37

Open luknow93 opened 4 years ago

luknow93 commented 4 years ago

Describe the bug When trying to upload a file thats exactly divisible by requestPayloadSize. An additional empty PATCH request will be made that will result in 404.

The cause of it is that in uploadChunk() method you're finishing connection after bytesRemainingForRequest is reaching 0. uploadChunk() doesn't return -1 at this point. On the server side the file is already "finished" since all bytes are there, but on the device an additional loop has to be made to receive -1 from uploadChunk(). But that additional call results in new connection being opened thats when being finished sends an empty body PATCH that results in 404 from the server, since for the server the upload already finished.

I guess a simple fix for that would be to move the openConnection() inside uploadChunk() a litte bit lower so that its called only if read didnt return -1

To Reproduce

  1. Follow the impl guide.
  2. Try to upload exactly 10MB file without changing any setup in uploader

Expected behavior No additional call when theres nothing left to upload.

Setup details Please provide following details, if applicable to your situation:

Acconut commented 4 years ago

I'm sorry for only responding now. You are absolutely correct in your analysis. Would you be willing to open a PR for your proposed patch?