@@ -138,18 +138,28 @@ static public void writeFile(String path, ReadableArray data, final boolean appe
138138 * @param promise
139139 */
140140 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 ;
142144 try {
143145 byte [] bytes ;
144146
145- if (path .startsWith (RNFetchBlobConst .FILE_PREFIX_BUNDLE_ASSET )) {
147+ if (resolved != null && resolved .startsWith (RNFetchBlobConst .FILE_PREFIX_BUNDLE_ASSET )) {
146148 String assetName = path .replace (RNFetchBlobConst .FILE_PREFIX_BUNDLE_ASSET , "" );
147149 long length = RNFetchBlob .RCTContext .getAssets ().openFd (assetName ).getLength ();
148150 bytes = new byte [(int ) length ];
149151 InputStream in = RNFetchBlob .RCTContext .getAssets ().open (assetName );
150152 in .read (bytes , 0 , (int ) length );
151153 in .close ();
152154 }
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+ }
153163 else {
154164 File f = new File (path );
155165 int length = (int ) f .length ();
@@ -226,17 +236,24 @@ static public String getTmpPath(ReactApplicationContext ctx, String taskId) {
226236 * @param bufferSize Buffer size of read stream, default to 4096 (4095 when encode is `base64`)
227237 */
228238 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 ;
230242 try {
231243
232244 int chunkSize = encoding .equalsIgnoreCase ("base64" ) ? 4095 : 4096 ;
233245 if (bufferSize > 0 )
234246 chunkSize = bufferSize ;
235247
236248 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 ));
240257 }
241258 else {
242259 fs = new FileInputStream (new File (path ));
0 commit comments