This repository has been archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Issue fetching files on Android #129
Comments
any workaround. Iam also facing same issue. Desktop its working fine but Android its failing |
I used this function to get the path where Android store the file fun getFilePath(
context: Context,
uri: Uri
): String? {
val returnCursor = context.contentResolver.query(uri, null, null, null, null)
val nameIndex = returnCursor!!.getColumnIndex(OpenableColumns.DISPLAY_NAME)
val sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE)
returnCursor.moveToFirst()
val name = returnCursor.getString(nameIndex)
returnCursor.getLong(sizeIndex).toString()
val file = File(context.filesDir, name)
try {
val inputStream: InputStream? = context.contentResolver.openInputStream(uri)
val outputStream = FileOutputStream(file)
var read = 0
val maxBufferSize = 1 * 1024 * 1024
val bytesAvailable: Int = inputStream?.available() ?: 0
val bufferSize = min(bytesAvailable, maxBufferSize)
val buffers = ByteArray(bufferSize)
while (inputStream?.read(buffers).also {
if (it != null) {
read = it
}
} != -1) {
outputStream.write(buffers, 0, read)
}
inputStream?.close()
outputStream.close()
} catch (_: Exception) {
} finally {
returnCursor.close()
}
return file.path
} For the |
it worked Thanks. |
I'm happy about this! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hi using the latest version of the multiple file picker (3.1.0) using the following snippet of code:
will be thrown the following exception:
Caused by: java.io.FileNotFoundException: /document/msf:59701: open failed: ENOENT (No such file or directory)
.There is a way to get directly the file from the Android's storage? Because using the
asset.path
it looks like does not get the complete path to get the fileThe text was updated successfully, but these errors were encountered: