Ver código fonte

Fix Download Manager bug when the file is not a multimedia #391

Ben Hsieh 7 anos atrás
pai
commit
ed2732a47e

+ 14
- 2
android/src/main/java/com/RNFetchBlob/RNFetchBlobReq.java Ver arquivo

@@ -150,6 +150,14 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
150 150
                 }
151 151
                 // set headers
152 152
                 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
+                }
153 161
                 while (it.hasNextKey()) {
154 162
                     String key = it.nextKey();
155 163
                     req.addRequestHeader(key, headers.getString(key));
@@ -636,16 +644,20 @@ public class RNFetchBlobReq extends BroadcastReceiver implements Runnable {
636 644
                         return;
637 645
                     }
638 646
                     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")) {
640 650
                         Uri uri = Uri.parse(contentUri);
641 651
                         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
643 654
                         if (cursor != null) {
644 655
                             cursor.moveToFirst();
645 656
                             filePath = cursor.getString(0);
646 657
                         }
647 658
                     }
648 659
                 }
660
+
649 661
                 // When the file is not found in media content database, check if custom path exists
650 662
                 if (options.addAndroidDownloads.hasKey("path")) {
651 663
                     try {