Skip to content

Commit

Permalink
fix cannot import file from download folder in android
Browse files Browse the repository at this point in the history
  • Loading branch information
Danh Nguyen committed Jul 30, 2019
1 parent e51bdd1 commit 95207a9
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,25 @@ public static String getRealPathFromURI(final Context context, final Uri uri) {
}
// DownloadsProvider
else if (isDownloadsDocument(uri)) {
try {
final String id = DocumentsContract.getDocumentId(uri);
//Starting with Android O, this "id" is not necessarily a long (row number),
//but might also be a "raw:/some/file/path" URL
if (id != null && id.startsWith("raw:/")) {
Uri rawuri = Uri.parse(id);
String path = rawuri.getPath();
return path;
}
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

final String id = DocumentsContract.getDocumentId(uri);
final Uri contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));

return getDataColumn(context, contentUri, null, null);
return getDataColumn(context, contentUri, null, null);
}
catch (Exception ex) {
//something went wrong, but android should still be able to handle the original uri by returning null here (see readFile(...))
return null;
}

}
// MediaProvider
else if (isMediaDocument(uri)) {
Expand Down

0 comments on commit 95207a9

Please sign in to comment.