我使用Fuel库为Kotlin下载图像。
以下代码可以显示下载状态...但是,Log.e("fetchProfileImage", "bytes --> ${bytes.size}")
行产生" 0"对于字节大小,所以我对发生的事情感到困惑。
这是预期的行为,还是我做错了什么?
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}")
})
}
}
以下是回复:
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]
答案 0 :(得分:1)