diff --git a/.github/ISSUE_TEMPLATE b/.github/ISSUE_TEMPLATE index 65d12bb4c..25e78c4cb 100644 --- a/.github/ISSUE_TEMPLATE +++ b/.github/ISSUE_TEMPLATE @@ -4,3 +4,4 @@ You may want to take a look on that page or find issues tagged "trouble shooting * please provide the version of installed library and RN project. * a sample code snippet/repository is very helpful to spotting the problem. * issues which have been tagged as 'needs feedback', will be closed after 2 weeks if receive no feedbacks. +* issues lack of detailed information will be closed without any feedback diff --git a/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java b/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java index e5742b81e..381a3f9f3 100644 --- a/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java +++ b/android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java @@ -8,6 +8,11 @@ import android.provider.MediaStore; import android.content.ContentUris; import android.os.Environment; +import android.content.ContentResolver; +import com.RNFetchBlob.RNFetchBlobUtils; +import java.io.File; +import java.io.InputStream; +import java.io.FileOutputStream; public class PathResolver { public static String getRealPathFromURI(final Context context, final Uri uri) { @@ -59,6 +64,29 @@ else if (isMediaDocument(uri)) { return getDataColumn(context, contentUri, selection, selectionArgs); } + // Other Providers + else { + try { + InputStream attachment = context.getContentResolver().openInputStream(uri); + if (attachment != null) { + String filename = getContentName(context.getContentResolver(), uri); + if (filename != null) { + File file = new File(context.getCacheDir(), filename); + FileOutputStream tmp = new FileOutputStream(file); + byte[] buffer = new byte[1024]; + while (attachment.read(buffer) > 0) { + tmp.write(buffer); + } + tmp.close(); + attachment.close(); + return file.getAbsolutePath(); + } + } + } catch (Exception e) { + RNFetchBlobUtils.emitWarningEvent(e.toString()); + return null; + } + } } // MediaStore (and general) else if ("content".equalsIgnoreCase(uri.getScheme())) { @@ -77,6 +105,18 @@ else if ("file".equalsIgnoreCase(uri.getScheme())) { return null; } + private static String getContentName(ContentResolver resolver, Uri uri) { + Cursor cursor = resolver.query(uri, null, null, null, null); + cursor.moveToFirst(); + int nameIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME); + if (nameIndex >= 0) { + String name = cursor.getString(nameIndex); + cursor.close(); + return name; + } + return null; + } + /** * Get the value of the data column for this Uri. This is useful for * MediaStore Uris, and other file-based ContentProviders.