Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fuel download returns empty bytes?

Tags:

android

kotlin

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]
like image 225
Dan Avatar asked Feb 23 '26 18:02

Dan


1 Answers

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

like image 65
Mark Gilchrist Avatar answered Feb 26 '26 09:02

Mark Gilchrist