Skip to content

Commit 8cca589

Browse files
committed
Fix upload of files >2GB to WebDAV
Fixes #531
1 parent 00d8199 commit 8cca589

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

data/src/main/java/org/cryptomator/data/cloud/webdav/network/InputStreamSourceBasedRequestBody.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,17 @@ internal class InputStreamSourceBasedRequestBody private constructor(private val
1313

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

1929
override fun contentType(): MediaType? {

0 commit comments

Comments
 (0)