Skip to content

Commit

Permalink
Fix upload of files >2GB to WebDAV
Browse files Browse the repository at this point in the history
Fixes #531
  • Loading branch information
SailReal committed Apr 18, 2024
1 parent 00d8199 commit 8cca589
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ internal class InputStreamSourceBasedRequestBody private constructor(private val

@Throws(IOException::class)
override fun contentLength(): Long {
return inputStream.available().toLong()
val availableBytes = inputStream.available()
/**
* inputStream.available() is an int and if the file to upload is > int.max it will overflow to 0.
* In this case we set contentLength to -1, which is fine, it just means the length is unknown.
* If inputStream.available() is actually 0, it does no harm either because we are not uploading a byte.
*/
return if (availableBytes != 0) {
availableBytes.toLong()
} else {
-1
}
}

override fun contentType(): MediaType? {
Expand Down

0 comments on commit 8cca589

Please sign in to comment.