Skip to content
This repository was archived by the owner on Mar 16, 2019. It is now read-only.

Commit 4d533a2

Browse files
committed
Fix #27 Android implementation
1 parent 6dceb8e commit 4d533a2

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/android/src/main/java/com/RNFetchBlob/RNFetchBlobFS.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,18 @@ static public void writeFile(String path, String encoding, String data, final Pr
6363
AsyncTask<String, Integer, Integer> task = new AsyncTask<String, Integer, Integer>() {
6464
@Override
6565
protected Integer doInBackground(String... args) {
66-
String path = args[0];
67-
String encoding = args[1];
68-
String data = args[2];
69-
File f = new File(path);
7066
try {
67+
String path = args[0];
68+
String encoding = args[1];
69+
String data = args[2];
70+
File f = new File(path);
71+
File dir = f.getParentFile();
72+
if(!dir.exists())
73+
dir.mkdirs();
7174
FileOutputStream fout = new FileOutputStream(f);
7275
fout.write(stringToBytes(data, encoding));
7376
fout.close();
74-
promise.resolve(null);
77+
promise.resolve(Arguments.createArray());
7578
} catch (Exception e) {
7679
promise.reject("RNFetchBlob writeFileError", e.getLocalizedMessage());
7780
}
@@ -88,13 +91,16 @@ protected Integer doInBackground(String... args) {
8891
* @param promise
8992
*/
9093
static public void writeFile(String path, ReadableArray data, final Promise promise) {
91-
AsyncTask<Object, Integer, Integer> task = new AsyncTask<Object, Integer, Integer>() {
94+
AsyncTask<Object, Void, Void> task = new AsyncTask<Object, Void, Void>() {
9295
@Override
93-
protected Integer doInBackground(Object... args) {
94-
String path = String.valueOf(args[0]);
95-
ReadableArray data = (ReadableArray) args[2];
96-
File f = new File(path);
96+
protected Void doInBackground(Object... args) {
9797
try {
98+
String path = (String)args[0];
99+
ReadableArray data = (ReadableArray) args[1];
100+
File f = new File(path);
101+
File dir = f.getParentFile();
102+
if(!dir.exists())
103+
dir.mkdirs();
98104
FileOutputStream os = new FileOutputStream(f);
99105
byte [] bytes = new byte[data.size()];
100106
for(int i=0;i<data.size();i++) {
@@ -119,7 +125,7 @@ protected Integer doInBackground(Object... args) {
119125
* @param promise
120126
*/
121127
static public void readFile(String path, String encoding, final Promise promise ) {
122-
AsyncTask task = new AsyncTask<String, Integer, Integer>() {
128+
AsyncTask<String, Integer, Integer> task = new AsyncTask<String, Integer, Integer>() {
123129
@Override
124130
protected Integer doInBackground(String... strings) {
125131
try {
@@ -140,7 +146,7 @@ protected Integer doInBackground(String... strings) {
140146
for(byte b : bytes) {
141147
asciiResult.pushInt((int)b);
142148
}
143-
promise.resolve(bytes);
149+
promise.resolve(asciiResult);
144150
break;
145151
case "utf8" :
146152
promise.resolve(new String(bytes));

0 commit comments

Comments
 (0)