Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit ed2732a

Browse files
committed
Fix Download Manager bug when the file is not a multimedia #391
1 parent c217fab commit ed2732a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ public void run() {
150150
}
151151
// set headers
152152
ReadableMapKeySetIterator it = headers.keySetIterator();
153+
// #391 Add MIME type to the request
154+
if(options.addAndroidDownloads.hasKey("mime")) {
155+
req.setMimeType(options.addAndroidDownloads.getString("mime"));
156+
}
157+
158+
if(options.addAndroidDownloads.hasKey("mediaScannable") && options.addAndroidDownloads.hasKey("mediaScannable") == true ) {
159+
req.allowScanningByMediaScanner();
160+
}
153161
while (it.hasNextKey()) {
154162
String key = it.nextKey();
155163
req.addRequestHeader(key, headers.getString(key));
@@ -636,16 +644,20 @@ public void onReceive(Context context, Intent intent) {
636644
return;
637645
}
638646
String contentUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
639-
if (contentUri != null) {
647+
if ( contentUri != null &&
648+
options.addAndroidDownloads.hasKey("mime") &&
649+
options.addAndroidDownloads.getString("mime").contains("image")) {
640650
Uri uri = Uri.parse(contentUri);
641651
Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
642-
// use default destination of DownloadManager
652+
653+
// use default destination of DownloadManager
643654
if (cursor != null) {
644655
cursor.moveToFirst();
645656
filePath = cursor.getString(0);
646657
}
647658
}
648659
}
660+
649661
// When the file is not found in media content database, check if custom path exists
650662
if (options.addAndroidDownloads.hasKey("path")) {
651663
try {

0 commit comments

Comments
 (0)