@@ -519,15 +519,15 @@ static void mkdir(String path, Promise promise) {
519
519
* @param callback JS context callback
520
520
*/
521
521
static void cp (String path , String dest , Callback callback ) {
522
- path = ReactNativeBlobUtilUtils .normalizePath (path );
523
522
dest = ReactNativeBlobUtilUtils .normalizePath (dest );
524
523
InputStream in = null ;
525
524
OutputStream out = null ;
526
525
String message = "" ;
527
526
528
527
try {
529
- if (!isPathExists (path )) {
530
- callback .invoke ("Source file at path`" + path + "` does not exist" );
528
+ in = inputStreamFromPath (path );
529
+ if (in == null ) {
530
+ callback .invoke ("Source file at path`" + path + "` does not exist or can not be opened" );
531
531
return ;
532
532
}
533
533
if (!new File (dest ).exists ()) {
@@ -538,7 +538,6 @@ static void cp(String path, String dest, Callback callback) {
538
538
}
539
539
}
540
540
541
- in = inputStreamFromPath (path );
542
541
out = new FileOutputStream (dest );
543
542
544
543
byte [] buf = new byte [10240 ];
@@ -1018,8 +1017,10 @@ protected Integer doInBackground(ReadableArray... paths) {
1018
1017
}
1019
1018
1020
1019
/**
1021
- * Get input stream of the given path, when the path is a string starts with bundle-assets://
1022
- * the stream is created by Assets Manager, otherwise use FileInputStream.
1020
+ * Get input stream of the given path.
1021
+ * When the path starts with bundle-assets:// the stream is created by Assets Manager
1022
+ * When the path starts with content:// the stream is created by ContentResolver
1023
+ * otherwise use FileInputStream.
1023
1024
*
1024
1025
* @param path The file to open stream
1025
1026
* @return InputStream instance
@@ -1029,7 +1030,10 @@ private static InputStream inputStreamFromPath(String path) throws IOException {
1029
1030
if (path .startsWith (ReactNativeBlobUtilConst .FILE_PREFIX_BUNDLE_ASSET )) {
1030
1031
return ReactNativeBlobUtilImpl .RCTContext .getAssets ().open (path .replace (ReactNativeBlobUtilConst .FILE_PREFIX_BUNDLE_ASSET , "" ));
1031
1032
}
1032
- return new FileInputStream (new File (path ));
1033
+ if (path .startsWith (ReactNativeBlobUtilConst .FILE_PREFIX_CONTENT )) {
1034
+ return ReactNativeBlobUtilImpl .RCTContext .getContentResolver ().openInputStream (Uri .parse (path ));
1035
+ }
1036
+ return new FileInputStream (new File (ReactNativeBlobUtilUtils .normalizePath (path )));
1033
1037
}
1034
1038
1035
1039
/**
0 commit comments