@@ -727,15 +727,15 @@ public void onScanCompleted(String s, Uri uri) {
727727 * @param encoding Encoding of initial data.
728728 * @param callback RCT bridge callback.
729729 */
730- static void createFile (String path , String data , String encoding , Callback callback ) {
730+ static void createFile (String path , String data , String encoding , Promise promise ) {
731731 try {
732732 File dest = new File (path );
733733 boolean created = dest .createNewFile ();
734734 if (encoding .equals (RNFetchBlobConst .DATA_ENCODE_URI )) {
735735 String orgPath = data .replace (RNFetchBlobConst .FILE_PREFIX , "" );
736736 File src = new File (orgPath );
737737 if (!src .exists ()) {
738- callback . invoke ("RNfetchBlob writeFileError" , "source file : " + data + "not exists" );
738+ promise . reject ("RNfetchBlob writeFileError" , "source file : " + data + "not exists" );
739739 return ;
740740 }
741741 FileInputStream fin = new FileInputStream (src );
@@ -751,15 +751,15 @@ static void createFile(String path, String data, String encoding, Callback callb
751751 }
752752 else {
753753 if (!created ) {
754- callback . invoke ("create file error: failed to create file at path `" + path + "` for its parent path may not exists, or the file already exists. If you intended to overwrite the existing file use fs.writeFile instead." );
754+ Promise . reject ("create file error: failed to create file at path `" + path + "` for its parent path may not exists, or the file already exists. If you intended to overwrite the existing file use fs.writeFile instead." );
755755 return ;
756756 }
757757 OutputStream ostream = new FileOutputStream (dest );
758758 ostream .write (RNFetchBlobFS .stringToBytes (data , encoding ));
759759 }
760- callback . invoke ( null , path );
760+ promise . resolve ( path );
761761 } catch (Exception err ) {
762- callback . invoke (err .getLocalizedMessage ());
762+ promise . reject (err .getLocalizedMessage ());
763763 }
764764 }
765765
@@ -769,16 +769,16 @@ static void createFile(String path, String data, String encoding, Callback callb
769769 * @param data Content of new file
770770 * @param callback JS context callback
771771 */
772- static void createFileASCII (String path , ReadableArray data , Callback callback ) {
772+ static void createFileASCII (String path , ReadableArray data , Promise promise ) {
773773 try {
774774 File dest = new File (path );
775775 if (dest .exists ()) {
776- callback . invoke ("create file error: failed to create file at path `" + path + "`, file already exists." );
776+ promise . reject ("create file error: failed to create file at path `" + path + "`, file already exists." );
777777 return ;
778778 }
779779 boolean created = dest .createNewFile ();
780780 if (!created ) {
781- callback . invoke ("create file error: failed to create file at path `" + path + "` for its parent path may not exists" );
781+ promise . reject ("create file error: failed to create file at path `" + path + "` for its parent path may not exists" );
782782 return ;
783783 }
784784 OutputStream ostream = new FileOutputStream (dest );
@@ -788,9 +788,9 @@ static void createFileASCII(String path, ReadableArray data, Callback callback)
788788 }
789789 ostream .write (chunk );
790790 chunk = null ;
791- callback . invoke ( null , path );
791+ promise . resolve ( path );
792792 } catch (Exception err ) {
793- callback . invoke (err .getLocalizedMessage ());
793+ promise . reject (err .getLocalizedMessage ());
794794 }
795795 }
796796
0 commit comments