gpt4 book ai didi

java - 尝试使用 Retrofit @Streaming 注释下载大文件时出现 OutOfMemoryError

转载 作者:行者123 更新时间:2023-11-29 22:55:14 27 4
gpt4 key购买 nike

我正在使用改造客户端下载文件,但是当有大文件 (200 MB) 时它抛出 java.lang.OutOfMemoryError:我也有@Streaming注解,这是我的下载服务方式

@Streaming
@GET("{path}")
suspend fun downloadFile(@Path("path") path: String): Response<ResponseBody>`

调用代码 fragment

suspend fun downloadFile(remotePath: String): FileDownloadResponse {
try {
val response = api.downloadFile(remotePath)
if (response.isSuccessful) {
FileDownloadResponse.Success(response.body()!!)
} else {
FileDownloadResponse.Fail()
}
} catch (e: Exception) {
e.printStakTrace()
FileDownloadResponse.Fail(throwable = e)

}

}

val response = remoteRepositroy.downloadFile(remotePath)
val writeResult = response.body.writeResponseBodyToDisk()

改造版本 = 2.6.0

协程版本 = 1.3.0-M1

最佳答案

我已通过将 HttpLogingInterceptor 日志级别从 BODY 更改为 HEADERS 来修复它

HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.HEADERS
})

看似奇怪的错误修复,但它有效

关于java - 尝试使用 Retrofit @Streaming 注释下载大文件时出现 OutOfMemoryError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57493076/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com