Skip to content

Commit 92e9a63

Browse files
authored
Merge pull request #226 from mgeier63/bug/225_
fixes [#225]
2 parents 37b0ecf + eccb467 commit 92e9a63

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,24 @@ public static String getRealPathFromURI(final Context context, final Uri uri) {
3737
}
3838
// DownloadsProvider
3939
else if (isDownloadsDocument(uri)) {
40+
try {
41+
final String id = DocumentsContract.getDocumentId(uri);
42+
//Starting with Android O, this "id" is not necessarily a long (row number),
43+
//but might also be a "raw:/some/file/path" URL
44+
if (id != null && id.startsWith("raw:/")) {
45+
Uri rawuri = Uri.parse(id);
46+
String path = rawuri.getPath();
47+
return path;
48+
}
49+
final Uri contentUri = ContentUris.withAppendedId(
50+
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
4051

41-
final String id = DocumentsContract.getDocumentId(uri);
42-
final Uri contentUri = ContentUris.withAppendedId(
43-
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
44-
45-
return getDataColumn(context, contentUri, null, null);
52+
return getDataColumn(context, contentUri, null, null);
53+
}
54+
catch (Exception ex) {
55+
//something went wrong, but android should still be able to handle the original uri by returning null here (see readFile(...))
56+
return null;
57+
}
4658
}
4759
// MediaProvider
4860
else if (isMediaDocument(uri)) {

0 commit comments

Comments
 (0)