diff --git a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/UploadLocalStorage.kt b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/UploadLocalStorage.kt index 737c2b3cf..4a48856ad 100644 --- a/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/UploadLocalStorage.kt +++ b/app/src/main/java/com/infomaniak/swisstransfer/ui/screen/newtransfer/UploadLocalStorage.kt @@ -51,19 +51,17 @@ class UploadLocalStorage @Inject constructor(@ApplicationContext private val app runCatching { createNewFile() }.onFailure { return null } runCatching { - val inputStream = appContext.contentResolver.openInputStream(uri) ?: run { + appContext.contentResolver.openInputStream(uri)?.use { inputStream -> + outputStream().use { outputStream -> + inputStream.copyTo(outputStream) + } + } ?: run { Sentry.withScope { scope -> scope.level = SentryLevel.ERROR Sentry.addBreadcrumb("During local copy of the file openInputStream returned null") } return null } - - inputStream.use { inputStream -> - outputStream().use { outputStream -> - inputStream.copyTo(outputStream) - } - } }.onFailure { Sentry.withScope { scope -> scope.level = SentryLevel.ERROR