mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-19 18:55:05 +01:00
Merge pull request #1441 from nextcloud/bugfix/1440/avoidExceptionInCopyFileToCache
catch FileNotFoundException in copyFileToCache
This commit is contained in:
commit
7ca2fc648d
@ -53,6 +53,7 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okhttp3.RequestBody
|
||||
import retrofit2.Response
|
||||
import java.io.File
|
||||
import java.io.FileNotFoundException
|
||||
import java.io.FileOutputStream
|
||||
import java.io.InputStream
|
||||
import java.util.ArrayList
|
||||
@ -167,13 +168,16 @@ class UploadAndShareFilesWorker(val context: Context, workerParameters: WorkerPa
|
||||
Log.d(TAG, "file is already in cache")
|
||||
} else {
|
||||
val outputStream = FileOutputStream(cachedFile)
|
||||
val inputStream: InputStream = context.contentResolver.openInputStream(sourceFileUri)!!
|
||||
|
||||
inputStream.use { input ->
|
||||
try {
|
||||
val inputStream: InputStream? = context.contentResolver.openInputStream(sourceFileUri)
|
||||
inputStream?.use { input ->
|
||||
outputStream.use { output ->
|
||||
input.copyTo(output)
|
||||
}
|
||||
}
|
||||
} catch (e: FileNotFoundException) {
|
||||
Log.w(TAG, "failed to copy file to cache", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user