|
|
|
|
1
|
package com.RNFetchBlob;
|
1
|
package com.RNFetchBlob;
|
2
|
|
2
|
|
3
|
import android.net.Uri;
|
3
|
import android.net.Uri;
|
|
|
4
|
+import android.os.Environment;
|
4
|
|
5
|
|
5
|
import com.facebook.react.bridge.Arguments;
|
6
|
import com.facebook.react.bridge.Arguments;
|
6
|
import com.facebook.react.bridge.Callback;
|
7
|
import com.facebook.react.bridge.Callback;
|
|
|
|
|
10
|
import com.facebook.react.bridge.ReadableArray;
|
11
|
import com.facebook.react.bridge.ReadableArray;
|
11
|
import com.facebook.react.bridge.ReadableMap;
|
12
|
import com.facebook.react.bridge.ReadableMap;
|
12
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
13
|
import com.facebook.react.bridge.ReadableMapKeySetIterator;
|
|
|
14
|
+import com.facebook.react.bridge.WritableArray;
|
13
|
import com.facebook.react.bridge.WritableMap;
|
15
|
import com.facebook.react.bridge.WritableMap;
|
14
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
16
|
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
15
|
import com.loopj.android.http.AsyncHttpClient;
|
17
|
import com.loopj.android.http.AsyncHttpClient;
|
|
|
|
|
34
|
return "RNFetchBlob";
|
36
|
return "RNFetchBlob";
|
35
|
}
|
37
|
}
|
36
|
|
38
|
|
|
|
39
|
+ @ReactMethod
|
|
|
40
|
+ public ReadableArray getSystemDirs() {
|
|
|
41
|
+
|
|
|
42
|
+ WritableArray results = Arguments.createArray();
|
|
|
43
|
+ ReactApplicationContext ctx = this.getReactApplicationContext();
|
|
|
44
|
+ results.pushString(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)));
|
|
|
45
|
+ results.pushString(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES)));
|
|
|
46
|
+ results.pushString(String.valueOf(ctx.getFilesDir()));
|
|
|
47
|
+ results.pushString(String.valueOf(ctx.getCacheDir()));
|
|
|
48
|
+ results.pushString(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC)));
|
|
|
49
|
+ results.pushString(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM)));
|
|
|
50
|
+ return results;
|
|
|
51
|
+ }
|
|
|
52
|
+
|
37
|
@ReactMethod
|
53
|
@ReactMethod
|
38
|
public void flush(String taskId) {
|
54
|
public void flush(String taskId) {
|
39
|
try {
|
55
|
try {
|
|
|
|
|
49
|
}
|
65
|
}
|
50
|
|
66
|
|
51
|
@ReactMethod
|
67
|
@ReactMethod
|
52
|
- public void readStream(String taskId, String encoding) {
|
|
|
|
|
68
|
+ public void readStream(String path, String encoding) {
|
53
|
RNFetchBlobFS fs = new RNFetchBlobFS(this.getReactApplicationContext());
|
69
|
RNFetchBlobFS fs = new RNFetchBlobFS(this.getReactApplicationContext());
|
54
|
- fs.readStream(taskId, encoding);
|
|
|
|
|
70
|
+ fs.readStream(path, encoding);
|
55
|
}
|
71
|
}
|
56
|
|
72
|
|
57
|
@ReactMethod
|
73
|
@ReactMethod
|
58
|
public void fetchBlob(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, final Callback callback) {
|
74
|
public void fetchBlob(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, final Callback callback) {
|
59
|
-
|
|
|
|
|
75
|
+ RNFetchBlobConfig config = new RNFetchBlobConfig(options);
|
60
|
try {
|
76
|
try {
|
61
|
Uri uri = Uri.parse(url);
|
77
|
Uri uri = Uri.parse(url);
|
62
|
AsyncHttpClient req = new AsyncHttpClient();
|
78
|
AsyncHttpClient req = new AsyncHttpClient();
|
|
|
|
|
87
|
AsyncHttpResponseHandler handler;
|
103
|
AsyncHttpResponseHandler handler;
|
88
|
|
104
|
|
89
|
// create handler
|
105
|
// create handler
|
90
|
- if(options.getBoolean("fileCache") || options.getString("path") != null)
|
|
|
91
|
- handler = new RNFetchBlobFileHandler(this.getReactApplicationContext(), taskId, callback);
|
|
|
|
|
106
|
+ if(config.fileCache || config.path != null)
|
|
|
107
|
+ handler = new RNFetchBlobFileHandler(this.getReactApplicationContext(), taskId, config, callback);
|
92
|
else
|
108
|
else
|
93
|
handler = new RNFetchBlobBinaryHandler(this.getReactApplicationContext(), taskId, callback);
|
109
|
handler = new RNFetchBlobBinaryHandler(this.getReactApplicationContext(), taskId, callback);
|
94
|
|
110
|
|
|
|
|
|
116
|
@ReactMethod
|
132
|
@ReactMethod
|
117
|
public void fetchBlobForm(ReadableMap options, String taskId, String method, String url, ReadableMap headers, ReadableArray body, final Callback callback) {
|
133
|
public void fetchBlobForm(ReadableMap options, String taskId, String method, String url, ReadableMap headers, ReadableArray body, final Callback callback) {
|
118
|
|
134
|
|
|
|
135
|
+ RNFetchBlobConfig config = new RNFetchBlobConfig(options);
|
119
|
try {
|
136
|
try {
|
120
|
Uri uri = Uri.parse(url);
|
137
|
Uri uri = Uri.parse(url);
|
121
|
AsyncHttpClient req = new AsyncHttpClient();
|
138
|
AsyncHttpClient req = new AsyncHttpClient();
|
|
|
|
|
177
|
AsyncHttpResponseHandler handler;
|
194
|
AsyncHttpResponseHandler handler;
|
178
|
|
195
|
|
179
|
// create handler
|
196
|
// create handler
|
180
|
- if(options.getBoolean("fileCache") || options.getString("path") != null)
|
|
|
181
|
- handler = new RNFetchBlobFileHandler(this.getReactApplicationContext(), taskId, callback);
|
|
|
|
|
197
|
+ if(config.fileCache || config.path != null)
|
|
|
198
|
+ handler = new RNFetchBlobFileHandler(this.getReactApplicationContext(), taskId, config, callback);
|
182
|
else
|
199
|
else
|
183
|
handler = new RNFetchBlobBinaryHandler(this.getReactApplicationContext(), taskId, callback);
|
200
|
handler = new RNFetchBlobBinaryHandler(this.getReactApplicationContext(), taskId, callback);
|
184
|
|
201
|
|