| 
				
			 | 
			
			
				@@ -1,8 +1,8 @@ 
			 | 
		
	
		
			
			| 
				1
			 | 
			
				1
			 | 
			
			
				 package com.RNFetchBlob; 
			 | 
		
	
		
			
			| 
				2
			 | 
			
				2
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				3
			 | 
			
				3
			 | 
			
			
				 import android.net.Uri; 
			 | 
		
	
		
			
			| 
				4
			 | 
			
				
			 | 
			
			
				-import android.text.style.AlignmentSpan; 
			 | 
		
	
		
			
			| 
				5
			 | 
			
				4
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				5
			 | 
			
			
				+import com.facebook.react.bridge.Arguments; 
			 | 
		
	
		
			
			| 
				6
			 | 
			
				6
			 | 
			
			
				 import com.facebook.react.bridge.Callback; 
			 | 
		
	
		
			
			| 
				7
			 | 
			
				7
			 | 
			
			
				 import com.facebook.react.bridge.ReactApplicationContext; 
			 | 
		
	
		
			
			| 
				8
			 | 
			
				8
			 | 
			
			
				 import com.facebook.react.bridge.ReactContextBaseJavaModule; 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -10,23 +10,17 @@ import com.facebook.react.bridge.ReactMethod; 
			 | 
		
	
		
			
			| 
				10
			 | 
			
				10
			 | 
			
			
				 import com.facebook.react.bridge.ReadableArray; 
			 | 
		
	
		
			
			| 
				11
			 | 
			
				11
			 | 
			
			
				 import com.facebook.react.bridge.ReadableMap; 
			 | 
		
	
		
			
			| 
				12
			 | 
			
				12
			 | 
			
			
				 import com.facebook.react.bridge.ReadableMapKeySetIterator; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				13
			 | 
			
			
				+import com.facebook.react.bridge.WritableMap; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				+import com.facebook.react.modules.core.DeviceEventManagerModule; 
			 | 
		
	
		
			
			| 
				13
			 | 
			
				15
			 | 
			
			
				 import com.loopj.android.http.AsyncHttpClient; 
			 | 
		
	
		
			
			| 
				14
			 | 
			
				16
			 | 
			
			
				 import com.loopj.android.http.AsyncHttpResponseHandler; 
			 | 
		
	
		
			
			| 
				15
			 | 
			
				17
			 | 
			
			
				 import com.loopj.android.http.Base64; 
			 | 
		
	
		
			
			| 
				16
			 | 
			
				
			 | 
			
			
				-import com.loopj.android.http.BinaryHttpResponseHandler; 
			 | 
		
	
		
			
			| 
				17
			 | 
			
				18
			 | 
			
			
				 import com.loopj.android.http.RequestParams; 
			 | 
		
	
		
			
			| 
				18
			 | 
			
				19
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				19
			 | 
			
				20
			 | 
			
			
				 import java.io.ByteArrayOutputStream; 
			 | 
		
	
		
			
			| 
				20
			 | 
			
				
			 | 
			
			
				-import java.nio.charset.Charset; 
			 | 
		
	
		
			
			| 
				21
			 | 
			
				
			 | 
			
			
				-import java.nio.charset.StandardCharsets; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				21
			 | 
			
			
				+import java.io.File; 
			 | 
		
	
		
			
			| 
				22
			 | 
			
				22
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				23
			 | 
			
				
			 | 
			
			
				-import cz.msebera.android.httpclient.Header; 
			 | 
		
	
		
			
			| 
				24
			 | 
			
				
			 | 
			
			
				-import cz.msebera.android.httpclient.entity.BufferedHttpEntity; 
			 | 
		
	
		
			
			| 
				25
			 | 
			
				23
			 | 
			
			
				 import cz.msebera.android.httpclient.entity.ByteArrayEntity; 
			 | 
		
	
		
			
			| 
				26
			 | 
			
				
			 | 
			
			
				-import cz.msebera.android.httpclient.entity.ContentType; 
			 | 
		
	
		
			
			| 
				27
			 | 
			
				
			 | 
			
			
				-import cz.msebera.android.httpclient.entity.StringEntity; 
			 | 
		
	
		
			
			| 
				28
			 | 
			
				
			 | 
			
			
				-import cz.msebera.android.httpclient.message.BasicHeader; 
			 | 
		
	
		
			
			| 
				29
			 | 
			
				
			 | 
			
			
				-import cz.msebera.android.httpclient.protocol.HTTP; 
			 | 
		
	
		
			
			| 
				30
			 | 
			
				24
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				31
			 | 
			
				25
			 | 
			
			
				 public class RNFetchBlob extends ReactContextBaseJavaModule { 
			 | 
		
	
		
			
			| 
				32
			 | 
			
				26
			 | 
			
			
				  
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -41,7 +35,27 @@ public class RNFetchBlob extends ReactContextBaseJavaModule { 
			 | 
		
	
		
			
			| 
				41
			 | 
			
				35
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				42
			 | 
			
				36
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				43
			 | 
			
				37
			 | 
			
			
				     @ReactMethod 
			 | 
		
	
		
			
			| 
				44
			 | 
			
				
			 | 
			
			
				-    public void fetchBlob(String taskId, String method, String url, ReadableMap headers, String body, final Callback callback) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				+    public void flush(String taskId) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+        try { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+            new File(RNFetchBlobFS.TempFilePath + taskId).delete(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+        } catch(Exception err) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+            WritableMap args = Arguments.createMap(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+            args.putString("event", "error"); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+            args.putString("detail", err.getMessage()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+            this.getReactApplicationContext() 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+                    .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+                    .emit("RNFetchBlobMessage", args); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+        } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+    @ReactMethod 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+    public void readStream(String taskId, String encoding) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+        RNFetchBlobFS fs = new RNFetchBlobFS(this.getReactApplicationContext()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+        fs.readStream(taskId, encoding); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+    @ReactMethod 
			 | 
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				+    public void fetchBlob(ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, final Callback callback) { 
			 | 
		
	
		
			
			| 
				45
			 | 
			
				59
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				46
			 | 
			
				60
			 | 
			
			
				         try { 
			 | 
		
	
		
			
			| 
				47
			 | 
			
				61
			 | 
			
			
				             Uri uri = Uri.parse(url); 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -70,8 +84,13 @@ public class RNFetchBlob extends ReactContextBaseJavaModule { 
			 | 
		
	
		
			
			| 
				70
			 | 
			
				84
			 | 
			
			
				                 entity.setContentType(headers.getString("Content-Type")); 
			 | 
		
	
		
			
			| 
				71
			 | 
			
				85
			 | 
			
			
				             } 
			 | 
		
	
		
			
			| 
				72
			 | 
			
				86
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				87
			 | 
			
			
				+            AsyncHttpResponseHandler handler; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				88
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				73
			 | 
			
				89
			 | 
			
			
				             // create handler 
			 | 
		
	
		
			
			| 
				74
			 | 
			
				
			 | 
			
			
				-            AsyncHttpResponseHandler handler = new RNFetchBlobHandler(this.getReactApplicationContext(), taskId, callback); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				90
			 | 
			
			
				+            if(options.getBoolean("fileCache") || options.getString("path") != null) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				91
			 | 
			
			
				+                handler = new RNFetchBlobFileHandler(this.getReactApplicationContext(), taskId, callback); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				92
			 | 
			
			
				+            else 
			 | 
		
	
		
			
			| 
				
			 | 
			
				93
			 | 
			
			
				+                handler = new RNFetchBlobBinaryHandler(this.getReactApplicationContext(), taskId, callback); 
			 | 
		
	
		
			
			| 
				75
			 | 
			
				94
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				76
			 | 
			
				95
			 | 
			
			
				             // send request 
			 | 
		
	
		
			
			| 
				77
			 | 
			
				96
			 | 
			
			
				             switch(method.toLowerCase()) { 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -95,7 +114,7 @@ public class RNFetchBlob extends ReactContextBaseJavaModule { 
			 | 
		
	
		
			
			| 
				95
			 | 
			
				114
			 | 
			
			
				     } 
			 | 
		
	
		
			
			| 
				96
			 | 
			
				115
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				97
			 | 
			
				116
			 | 
			
			
				     @ReactMethod 
			 | 
		
	
		
			
			| 
				98
			 | 
			
				
			 | 
			
			
				-    public void fetchBlobForm(String taskId, String method, String url, ReadableMap headers, ReadableArray body, final Callback callback) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				117
			 | 
			
			
				+    public void fetchBlobForm(ReadableMap options, String taskId, String method, String url, ReadableMap headers, ReadableArray body, final Callback callback) { 
			 | 
		
	
		
			
			| 
				99
			 | 
			
				118
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				100
			 | 
			
				119
			 | 
			
			
				         try { 
			 | 
		
	
		
			
			| 
				101
			 | 
			
				120
			 | 
			
			
				             Uri uri = Uri.parse(url); 
			 | 
		
	
	
		
			
			| 
				
			 | 
			
			
				@@ -155,8 +174,13 @@ public class RNFetchBlob extends ReactContextBaseJavaModule { 
			 | 
		
	
		
			
			| 
				155
			 | 
			
				174
			 | 
			
			
				                 req.addHeader("Content-Type", headers.getString("Content-Type") + "; charset=utf8; boundary=" + boundary); 
			 | 
		
	
		
			
			| 
				156
			 | 
			
				175
			 | 
			
			
				             } 
			 | 
		
	
		
			
			| 
				157
			 | 
			
				176
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				
			 | 
			
				177
			 | 
			
			
				+            AsyncHttpResponseHandler handler; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				178
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				158
			 | 
			
				179
			 | 
			
			
				             // create handler 
			 | 
		
	
		
			
			| 
				159
			 | 
			
				
			 | 
			
			
				-            AsyncHttpResponseHandler handler = new RNFetchBlobHandler(this.getReactApplicationContext(), taskId, callback); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				180
			 | 
			
			
				+            if(options.getBoolean("fileCache") || options.getString("path") != null) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				181
			 | 
			
			
				+                handler = new RNFetchBlobFileHandler(this.getReactApplicationContext(), taskId, callback); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				182
			 | 
			
			
				+            else 
			 | 
		
	
		
			
			| 
				
			 | 
			
				183
			 | 
			
			
				+                handler = new RNFetchBlobBinaryHandler(this.getReactApplicationContext(), taskId, callback); 
			 | 
		
	
		
			
			| 
				160
			 | 
			
				184
			 | 
			
			
				  
			 | 
		
	
		
			
			| 
				161
			 | 
			
				185
			 | 
			
			
				             // send request 
			 | 
		
	
		
			
			| 
				162
			 | 
			
				186
			 | 
			
			
				             switch(method.toLowerCase()) { 
			 |