I'm working on an app that uploads videos to Vimeo using the TUS approach.
I wrote a simple wrapper for Fast Android Networking to use for uploading each part of the video file.
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)
}
})
}
This seems to fail inconsistently, it sometimes works fine, and sometimes it doesn't. The parts uploaded are 70MB in size. The error thrown is:
com.androidnetworking.error.ANError: okhttp3.internal.http2.StreamResetException: stream was reset: NO_ERROR
Normally, I recover from errors by retrying the upload as TUS specifies, however, after getting the resources and retrying the patch, the network activity drops significantly (from a few Mbps to a few Kbps), and eventually a socket timeout occurs:
com.androidnetworking.error.ANError: java.net.SocketTimeoutException: timeout
Any ideas on what might be wrong here?
I ended up using OkHttp3 directly to upload the data to Vimeo. Here's my solution: