【发布时间】:2020-03-16 09:34:54
【问题描述】:
我正在开发一个使用 TUS 方法将视频上传到 Vimeo 的应用程序。
我为 Fast Android Networking 编写了一个简单的包装器,用于上传视频文件的每个部分。
fun patch(
destination: RequestDestination = RequestDestination.Api,
url: String,
headers: Map<String, Any> = mapOf(),
body: ByteArray? = null,
contentType: String? = null,
priority: Priority = Priority.MEDIUM,
jsonRequest: Boolean = true,
success: (Any?) -> Unit,
failure: (ANError?) -> Unit
) {
val requestUrlString = getFullUrl(destination, url) // Determines the destination URL, is working correctly
val request = AndroidNetworking.patch(requestUrlString)
setRequestAttributes(request, headers, destination, priority) // Adds the request params, headers, etc to the request, works correctly
if (contentType != null) {
request.setContentType(contentType)
}
if (body != null) {
request.addByteBody(body)
}
request.build().getAsOkHttpResponse(object : OkHttpResponseListener {
override fun onResponse(response: Response?) {
success(response)
}
override fun onError(anError: ANError?) {
failure(anError)
}
})
}
这似乎不一致地失败,有时可以正常工作,有时不能。 上传的部分大小为 70MB。 抛出的错误是:
com.androidnetworking.error.ANError: okhttp3.internal.http2.StreamResetException: stream was reset: NO_ERROR
通常,我通过按照 TUS 指定的方式重试上传来从错误中恢复,但是,在获取资源并重试补丁后,网络活动显着下降(从几 Mbps 到几 Kbps),最终发生套接字超时:
com.androidnetworking.error.ANError: java.net.SocketTimeoutException: timeout
关于这里可能有什么问题的任何想法?
【问题讨论】:
标签: android kotlin okhttp fast-android-networking