gotev / android-upload-service

Easily upload files (Multipart/Binary/FTP out of the box) in the background with progress notification. Support for persistent upload requests, customizations and custom plugins.
Apache License 2.0
2.83k stars 690 forks source link

Actual file size is not matched with upload file size shown in UploadService #626

Closed devdivr closed 1 year ago

devdivr commented 1 year ago

Hi, I try to upload a file to Google Cloud Bucket but have failed to complete even though it works to upload itself. Actual file size I tried to upload is 327307520 bytes but android-upload-service recognize it as 327307740 bytes with 220 bytes of difference observing with GlobalUploadObserver. I couldn't find any bugs on my code but just wonder why UploadService reads the file as 327307740 bytes. Would be much helpful if you could let me known.

Request

// localItem.size which means 327307520 bytes
MultipartUploadRequest(
   context,
   serverUrl = location
)
.setMethod("PUT")
.addHeader("Content-Length", "${localItem.size}")
.addHeader("X-Goog-Content-Length-Range", "0,${localItem.size}")
.addFileToUpload(filePath, parameterName = "file", localItem.name)
.setUploadID(localItem.id)
.startUpload()

UploadService Info

UploadService - (uploadId: N/A) - Starting UploadService. Debug info: {
  "uploadServiceVersion": "4.7.0",
  "androidApiVersion": 30,
  "namespace": "com.bepro11.analytics.beta",
  "deviceProcessors": 4,
  "idleTimeoutSeconds": 10,
  "bufferSizeBytes": 4096,
  "httpStack": "net.gotev.uploadservice.network.hurl.HurlStack",
  "uploadProgressNotificationIntervalMillis": 333,
  "retryPolicy": {"initialWaitTimeSeconds": 1, "maxWaitTimeSeconds": 100, "multiplier": 2, "defaultMaxRetries": 3},
  "isForegroundService": true,
  "schemeHandlers": {"/": "net.gotev.uploadservice.schemehandlers.FileSchemeHandler", "content://": "net.gotev.uploadservice.schemehandlers.ContentResolverSchemeHandler"}
}

Logcat from UploadService

UploadTask - (uploadId: fd66a688-367d-41bd-afae-1895e6e8b74c) - uploaded 1%, 4145323 of 327307740 bytes
gotev commented 1 year ago

Hey @devdivr

fist of all, Upload Service measures file sizes in those ways:

so as a first step it's important to know which of the two implementations is used in your specific case.

Then, how have you measured 327307520 size?

The multipart request you're using is tested both with this test suite and also against a real node.js express server which is in the examples. If you want to make some tests on your dev pc, you can easily replicate the setup by following this guide: https://github.com/gotev/android-upload-service/wiki/Upload-Service-Testbed or you can write a test which replicates this case.

At this stage there's nothing more I can say about your specific question without further evidence.

devdivr commented 1 year ago

BinaryUploadRequest made it. I don't know why but Multipart upload has more data in it?

gotev commented 1 year ago

@devdivr yes, take a look here and the linked RFC: https://github.com/gotev/android-upload-service/wiki/4.x-Usage#http-multipartform-data-upload--rfc2388 Multipart Upload Protocol has boundary bytes to allow for data and parameters in a single request, therefore if you observe the request from a server, you'll see more bytes than a Binary upload.