Browse Source

Merge branch '0.10.6' of github.com:wkh237/react-native-fetch-blob into 0.10.6

Ben Hsieh 7 years ago
parent
commit
be00a24908
4 changed files with 54 additions and 2 deletions
  1. 12
    0
      CONTRIBUTORS.md
  2. 40
    0
      android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java
  3. 0
    1
      index.js
  4. 2
    1
      package.json

+ 12
- 0
CONTRIBUTORS.md View File

1
 960px <pinovel@gmail.com>
1
 960px <pinovel@gmail.com>
2
 Andreas Amsenius <andreas@amsenius.se>
2
 Andreas Amsenius <andreas@amsenius.se>
3
+Andrew Jack <me@andrewjack.uk>
3
 Arthur Ouaki <arthur.ouaki@gmail.com>
4
 Arthur Ouaki <arthur.ouaki@gmail.com>
4
 Binur Konarbai <binur95@gmail.com>
5
 Binur Konarbai <binur95@gmail.com>
6
+Bronco <heybronco@gmail.com>
5
 Chris Sloey <chris@addjam.com>
7
 Chris Sloey <chris@addjam.com>
6
 Corentin Smith <corentin.smith@gmail.com>
8
 Corentin Smith <corentin.smith@gmail.com>
7
 Dmitry Petukhov <dmitryvpetukhov@gmail.com>
9
 Dmitry Petukhov <dmitryvpetukhov@gmail.com>
9
 Erik Smartt <code@eriksmartt.com>
11
 Erik Smartt <code@eriksmartt.com>
10
 Evgeniy Baraniuk <ev.baraniuk@gmail.com>
12
 Evgeniy Baraniuk <ev.baraniuk@gmail.com>
11
 Frank van der Hoek <frank.vanderhoek@gmail.com>
13
 Frank van der Hoek <frank.vanderhoek@gmail.com>
14
+Guy Blank <blank.guy@gmail.com>
15
+Jon San Miguel <sanmiguelje@gmail.com>
12
 Juan B. Rodriguez <jbrodriguez@gmail.com>
16
 Juan B. Rodriguez <jbrodriguez@gmail.com>
13
 Kaishley <kklingachetti@msn.com>
17
 Kaishley <kklingachetti@msn.com>
14
 Martin Giachetti <martin.giachetti@gmail.com>
18
 Martin Giachetti <martin.giachetti@gmail.com>
19
+Max Gurela <maxpowa1@gmail.com>
15
 Mike Monteith <mike@mikemonteith.com>
20
 Mike Monteith <mike@mikemonteith.com>
16
 Naoki AINOYA <ainonic@gmail.com>
21
 Naoki AINOYA <ainonic@gmail.com>
17
 Nguyen Cao Nhat Linh <nhatlinh95@gmail.com>
22
 Nguyen Cao Nhat Linh <nhatlinh95@gmail.com>
23
+Nick Pomfret <npomfret@users.noreply.github.com>
24
+Oliver <spendabuk@hotmail.com>
18
 Petter Hesselberg <petterh@microsoft.com>
25
 Petter Hesselberg <petterh@microsoft.com>
26
+Reza Ghorbani <r.ghorbani.f@gmail.com>
27
+Steve Liles <steveliles@gmail.com>
19
 Tim Suchanek <tim.suchanek@gmail.com>
28
 Tim Suchanek <tim.suchanek@gmail.com>
29
+Yonsh Lin <yonsh@live.com>
30
+atlanteh <atlanteh@gmail.com>
20
 follower <github@rancidbacon.com>
31
 follower <github@rancidbacon.com>
21
 francisco-sanchez-molina <psm1984@gmail.com>
32
 francisco-sanchez-molina <psm1984@gmail.com>
33
+gferreyra91 <gferreyra91@gmail.com>
22
 hhravn <hhravn@gmail.com>
34
 hhravn <hhravn@gmail.com>
23
 kejinliang <kejinliang@users.noreply.github.com>
35
 kejinliang <kejinliang@users.noreply.github.com>
24
 pedramsaleh <spmact@yahoo.ca>
36
 pedramsaleh <spmact@yahoo.ca>

+ 40
- 0
android/src/main/java/com/RNFetchBlob/Utils/PathResolver.java View File

8
 import android.provider.MediaStore;
8
 import android.provider.MediaStore;
9
 import android.content.ContentUris;
9
 import android.content.ContentUris;
10
 import android.os.Environment;
10
 import android.os.Environment;
11
+import android.content.ContentResolver;
12
+import com.RNFetchBlob.RNFetchBlobUtils;
13
+import java.io.File;
14
+import java.io.InputStream;
15
+import java.io.FileOutputStream;
11
 
16
 
12
 public class PathResolver {
17
 public class PathResolver {
13
     public static String getRealPathFromURI(final Context context, final Uri uri) {
18
     public static String getRealPathFromURI(final Context context, final Uri uri) {
59
 
64
 
60
                 return getDataColumn(context, contentUri, selection, selectionArgs);
65
                 return getDataColumn(context, contentUri, selection, selectionArgs);
61
             }
66
             }
67
+            // Other Providers
68
+            else {
69
+                try {
70
+                    InputStream attachment = context.getContentResolver().openInputStream(uri);
71
+                    if (attachment != null) {
72
+                        String filename = getContentName(context.getContentResolver(), uri);
73
+                        if (filename != null) {
74
+                            File file = new File(context.getCacheDir(), filename);
75
+                            FileOutputStream tmp = new FileOutputStream(file);
76
+                            byte[] buffer = new byte[1024];
77
+                            while (attachment.read(buffer) > 0) {
78
+                                tmp.write(buffer);
79
+                            }
80
+                            tmp.close();
81
+                            attachment.close();
82
+                            return file.getAbsolutePath();
83
+                        }
84
+                    }
85
+                } catch (Exception e) {
86
+                    RNFetchBlobUtils.emitWarningEvent(e.toString());
87
+                    return null;
88
+                }
89
+            }
62
         }
90
         }
63
         // MediaStore (and general)
91
         // MediaStore (and general)
64
         else if ("content".equalsIgnoreCase(uri.getScheme())) {
92
         else if ("content".equalsIgnoreCase(uri.getScheme())) {
77
         return null;
105
         return null;
78
     }
106
     }
79
 
107
 
108
+    private static String getContentName(ContentResolver resolver, Uri uri) {
109
+        Cursor cursor = resolver.query(uri, null, null, null, null);
110
+        cursor.moveToFirst();
111
+        int nameIndex = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
112
+        if (nameIndex >= 0) {
113
+            String name = cursor.getString(nameIndex);
114
+            cursor.close();
115
+            return name;
116
+        }
117
+        return null;
118
+    }
119
+
80
     /**
120
     /**
81
      * Get the value of the data column for this Uri. This is useful for
121
      * Get the value of the data column for this Uri. This is useful for
82
      * MediaStore Uris, and other file-based ContentProviders.
122
      * MediaStore Uris, and other file-based ContentProviders.

+ 0
- 1
index.js View File

50
 // their .expire event
50
 // their .expire event
51
 if(Platform.OS === 'ios') {
51
 if(Platform.OS === 'ios') {
52
   AppState.addEventListener('change', (e) => {
52
   AppState.addEventListener('change', (e) => {
53
-    console.log('app state changed', e)
54
     if(e === 'active')
53
     if(e === 'active')
55
       RNFetchBlob.emitExpiredEvent(()=>{})
54
       RNFetchBlob.emitExpiredEvent(()=>{})
56
   })
55
   })

+ 2
- 1
package.json View File

32
   "author": "wkh237 <xeiyan@gmail.com>",
32
   "author": "wkh237 <xeiyan@gmail.com>",
33
   "license": "MIT",
33
   "license": "MIT",
34
   "contributors": [
34
   "contributors": [
35
+    "Ben <benhsieh@catchplay.com>",
35
     ""
36
     ""
36
   ]
37
   ]
37
-}
38
+}