You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I have an Android application that needs to upload a local temp file to a server. At runtime I receive the following error:
The inputs have already been written to an output stream and can not be consumed again.
com.github.kittinunf.fuel.core.FuelError$Companion.wrap(FuelError.kt:86)
com.github.kittinunf.fuel.core.FuelError$Companion.wrap$default(FuelError.kt:83)
Caused by: java.lang.IllegalStateException: The inputs have already been written to an output stream and can not be consumed again.
com.github.kittinunf.fuel.core.requests.UploadBody.writeTo(UploadBody.kt:100)
com.github.kittinunf.fuel.toolbox.HttpClient.setBodyIfDoOutput(HttpClient.kt:273)
com.github.kittinunf.fuel.toolbox.HttpClient.sendRequest(HttpClient.kt:140)
com.github.kittinunf.fuel.toolbox.HttpClient.doRequest(HttpClient.kt:79)
com.github.kittinunf.fuel.toolbox.HttpClient.executeRequest(HttpClient.kt:37)
com.github.kittinunf.fuel.core.requests.RequestTask.executeRequest(RequestTask.kt:23)
com.github.kittinunf.fuel.core.requests.RequestTask.call(RequestTask.kt:44)
com.github.kittinunf.fuel.core.requests.RequestTask.call(RequestTask.kt:14)
com.github.kittinunf.fuel.core.requests.RequestTaskCallbacks.call(RequestTaskCallbacks.kt:28)
com.github.kittinunf.fuel.core.requests.RequestTaskCallbacks.call(RequestTaskCallbacks.kt:20)
java.util.concurrent.FutureTask.run(FutureTask.java:266)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
java.lang.Thread.run(Thread.java:764)
privatesuspendfunuploadFile(localPath:String): String {
val bearerToken = authenticate() //retrieves a jwt bearer tokenval url ="***REDACTED***"//simple upload endpoint that accepts multipart/form-data file and saves it elsewhere
withContext(Dispatchers.IO) {
Fuel.upload(url, Method.POST)
.authentication()
.bearer(bearerToken)
.upload()
.add { FileDataPart(File(localPath), name ="file", filename ="input.pdf", contentType =PDF_MIME_TYPE) }
.progress { readBytes, totalBytes ->if (readBytes >0&& totalBytes >0) {
val progress:Int= (readBytes.toFloat() / totalBytes.toFloat() *100).toInt()
Log.d(TAG, "Upload progress: $progress%")
}
}
.responseString { _, _, result ->
result.fold({
Log.d(TAG, "Upload completed")
}, { error ->Log.e(TAG, "Unable to upload the file", error)
})
}
.awaitUnit()
}
}
The file localPath should not be locked by anyone else. I've even make a copy of it and pass the copy to Fuel to double check but it returns the same error. Could it be a bug?
Thanks in advance
The text was updated successfully, but these errors were encountered:
Hi, I have an Android application that needs to upload a local temp file to a server. At runtime I receive the following error:
The android version is the following:
Those are my dependencies:
And this is the code I'm using to upload:
The file
localPath
should not be locked by anyone else. I've even make a copy of it and pass the copy to Fuel to double check but it returns the same error. Could it be a bug?Thanks in advance
The text was updated successfully, but these errors were encountered: