From eccb467ed61517197f8e855e85cd1dc12266683c Mon Sep 17 00:00:00 2001 From: Marco Geier Date: Wed, 31 Oct 2018 16:57:50 +0700 Subject: [PATCH] fixes [joltup/rn-fetch-blob#225] --- .../com/RNFetchBlob/Utils/PathResolver.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java b/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java index de72ecaa1..82b10888b 100644 --- a/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java +++ b/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java @@ -37,12 +37,24 @@ 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)) {