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

Commit

Permalink
Fix Download Manager bug when the file is not a multimedia #391
Browse files Browse the repository at this point in the history
  • Loading branch information
wkh237 committed Jul 5, 2017
1 parent c217fab commit ed2732a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ public void run() {
}
// set headers
ReadableMapKeySetIterator it = headers.keySetIterator();
// #391 Add MIME type to the request
if(options.addAndroidDownloads.hasKey("mime")) {
req.setMimeType(options.addAndroidDownloads.getString("mime"));
}

if(options.addAndroidDownloads.hasKey("mediaScannable") && options.addAndroidDownloads.hasKey("mediaScannable") == true ) {
req.allowScanningByMediaScanner();
}
while (it.hasNextKey()) {
String key = it.nextKey();
req.addRequestHeader(key, headers.getString(key));
Expand Down Expand Up @@ -636,16 +644,20 @@ public void onReceive(Context context, Intent intent) {
return;
}
String contentUri = c.getString(c.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI));
if (contentUri != null) {
if ( contentUri != null &&
options.addAndroidDownloads.hasKey("mime") &&
options.addAndroidDownloads.getString("mime").contains("image")) {
Uri uri = Uri.parse(contentUri);
Cursor cursor = appCtx.getContentResolver().query(uri, new String[]{android.provider.MediaStore.Images.ImageColumns.DATA}, null, null, null);
// use default destination of DownloadManager

// use default destination of DownloadManager
if (cursor != null) {
cursor.moveToFirst();
filePath = cursor.getString(0);
}
}
}

// When the file is not found in media content database, check if custom path exists
if (options.addAndroidDownloads.hasKey("path")) {
try {
Expand Down

0 comments on commit ed2732a

Please sign in to comment.