I'm using Fuel library for Kotlin to download an image.
The following code works as far as showing the download status ... but, the Log.e("fetchProfileImage", "bytes --> ${bytes.size}") line yields "0" for byte size, so I'm confused as to what's going on.
Is this the expected behavior, or am I doing something wrong?
Fuel.download(endpoint).destination { response, url ->
File.createTempFile("profileImage", ".jpg")
}.progress { readBytes, totalBytes ->
val fractionCompleted = readBytes.toFloat() / totalBytes.toFloat()
this.delegate?.downloadProgressDidChange(to = fractionCompleted)
}.response { request, response, result ->
val (data, error) = result
if (error != null) {
Log.e("fetchProfileImage", "error: ${error}")
} else {
result.fold({ bytes ->
Log.e("fetchProfileImage", "bytes --> ${bytes.size}")
// delegate?.didReceiveProfileImage(bmp)
}, {err ->
Log.e("fetchProfileImage", "error: ${err}")
})
}
}
Here's the response:
Response : OK
Length : 426828
Body : (426828 bytes of image/jpeg)
Headers : (8)
Content-Length : [426828]
Content-Type : [image/jpeg]
Date : [Mon, 12 Feb 2018 04:10:27 GMT]
Server : [Jetty(9.4.3.v20170317)]
X-Android-Received-Millis : [1518408627531]
X-Android-Response-Source : [NETWORK 200]
X-Android-Selected-Protocol : [http/1.1]
X-Android-Sent-Millis : [1518408627121]
This is a problem with the internal workings of Fuel
I have raised a pr that fixes this issue (in a suitable manner I hope) https://github.com/kittinunf/Fuel/issues/275
This is not something you as a user have done wrong
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With