|
@@ -79,7 +79,25 @@ public class RNFetchBlobFS {
|
79
|
79
|
if(!dir.exists())
|
80
|
80
|
dir.mkdirs();
|
81
|
81
|
FileOutputStream fout = new FileOutputStream(f, append);
|
82
|
|
- fout.write(stringToBytes(data, encoding));
|
|
82
|
+ // write data from a file
|
|
83
|
+ if(encoding.equalsIgnoreCase(RNFetchBlobConst.DATA_ENCODE_URI)) {
|
|
84
|
+ File src = new File(data);
|
|
85
|
+ if(!src.exists()) {
|
|
86
|
+ promise.reject("RNfetchBlob writeFileError", "source file : " + data + "not exists");
|
|
87
|
+ fout.close();
|
|
88
|
+ return null;
|
|
89
|
+ }
|
|
90
|
+ FileInputStream fin = new FileInputStream(src);
|
|
91
|
+ byte [] buffer = new byte [10240];
|
|
92
|
+ int read = fin.read(buffer);
|
|
93
|
+ while(read > 0) {
|
|
94
|
+ fout.write(buffer, 0, read);
|
|
95
|
+ read = fin.read(buffer);
|
|
96
|
+ }
|
|
97
|
+ fin.close();
|
|
98
|
+ }
|
|
99
|
+ else
|
|
100
|
+ fout.write(stringToBytes(data, encoding));
|
83
|
101
|
fout.close();
|
84
|
102
|
promise.resolve(Arguments.createArray());
|
85
|
103
|
} catch (Exception e) {
|