|
@@ -138,11 +138,13 @@ public class RNFetchBlobFS {
|
138
|
138
|
* @param promise
|
139
|
139
|
*/
|
140
|
140
|
static public void readFile(String path, String encoding, final Promise promise ) {
|
141
|
|
- path = normalizePath(path);
|
|
141
|
+ String resolved = normalizePath(path);
|
|
142
|
+ if(resolved != null)
|
|
143
|
+ path = resolved;
|
142
|
144
|
try {
|
143
|
145
|
byte[] bytes;
|
144
|
146
|
|
145
|
|
- if(path.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) {
|
|
147
|
+ if(resolved != null && resolved.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) {
|
146
|
148
|
String assetName = path.replace(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET, "");
|
147
|
149
|
long length = RNFetchBlob.RCTContext.getAssets().openFd(assetName).getLength();
|
148
|
150
|
bytes = new byte[(int) length];
|
|
@@ -150,6 +152,14 @@ public class RNFetchBlobFS {
|
150
|
152
|
in.read(bytes, 0, (int) length);
|
151
|
153
|
in.close();
|
152
|
154
|
}
|
|
155
|
+ // issue 287
|
|
156
|
+ else if(resolved == null) {
|
|
157
|
+ InputStream in = RNFetchBlob.RCTContext.getContentResolver().openInputStream(Uri.parse(path));
|
|
158
|
+ int length = (int) in.available();
|
|
159
|
+ bytes = new byte[length];
|
|
160
|
+ in.read(bytes);
|
|
161
|
+ in.close();
|
|
162
|
+ }
|
153
|
163
|
else {
|
154
|
164
|
File f = new File(path);
|
155
|
165
|
int length = (int) f.length();
|
|
@@ -226,7 +236,9 @@ public class RNFetchBlobFS {
|
226
|
236
|
* @param bufferSize Buffer size of read stream, default to 4096 (4095 when encode is `base64`)
|
227
|
237
|
*/
|
228
|
238
|
public void readStream(String path, String encoding, int bufferSize, int tick, final String streamId) {
|
229
|
|
- path = normalizePath(path);
|
|
239
|
+ String resolved = normalizePath(path);
|
|
240
|
+ if(resolved != null)
|
|
241
|
+ path = resolved;
|
230
|
242
|
try {
|
231
|
243
|
|
232
|
244
|
int chunkSize = encoding.equalsIgnoreCase("base64") ? 4095 : 4096;
|
|
@@ -234,9 +246,14 @@ public class RNFetchBlobFS {
|
234
|
246
|
chunkSize = bufferSize;
|
235
|
247
|
|
236
|
248
|
InputStream fs;
|
237
|
|
- if(path.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) {
|
238
|
|
- fs = RNFetchBlob.RCTContext.getAssets()
|
239
|
|
- .open(path.replace(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET, ""));
|
|
249
|
+
|
|
250
|
+ if(resolved != null && path.startsWith(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET)) {
|
|
251
|
+ fs = RNFetchBlob.RCTContext.getAssets().open(path.replace(RNFetchBlobConst.FILE_PREFIX_BUNDLE_ASSET, ""));
|
|
252
|
+
|
|
253
|
+ }
|
|
254
|
+ // fix issue 287
|
|
255
|
+ else if(resolved == null) {
|
|
256
|
+ fs = RNFetchBlob.RCTContext.getContentResolver().openInputStream(Uri.parse(path));
|
240
|
257
|
}
|
241
|
258
|
else {
|
242
|
259
|
fs = new FileInputStream(new File(path));
|