| 
				
			 | 
			
			
				@@ -0,0 +1,205 @@ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				1
			 | 
			
			
				+package com.RNFetchBlob; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				2
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				3
			 | 
			
			
				+import com.facebook.react.bridge.Callback; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				4
			 | 
			
			
				+import com.facebook.react.bridge.ReactApplicationContext; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				5
			 | 
			
			
				+import com.facebook.react.bridge.ReadableArray; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				6
			 | 
			
			
				+import com.facebook.react.bridge.ReadableMap; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				7
			 | 
			
			
				+import com.facebook.react.bridge.ReadableMapKeySetIterator; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				8
			 | 
			
			
				+import com.loopj.android.http.AsyncHttpClient; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				9
			 | 
			
			
				+import com.loopj.android.http.AsyncHttpResponseHandler; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				10
			 | 
			
			
				+import com.loopj.android.http.Base64; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				11
			 | 
			
			
				+import com.loopj.android.http.MySSLSocketFactory; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				12
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				13
			 | 
			
			
				+import java.io.File; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				14
			 | 
			
			
				+import java.nio.charset.Charset; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				15
			 | 
			
			
				+import java.security.KeyStore; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				16
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				17
			 | 
			
			
				+import cz.msebera.android.httpclient.HttpEntity; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				18
			 | 
			
			
				+import cz.msebera.android.httpclient.entity.AbstractHttpEntity; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				19
			 | 
			
			
				+import cz.msebera.android.httpclient.entity.ByteArrayEntity; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				20
			 | 
			
			
				+import cz.msebera.android.httpclient.entity.ContentType; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				21
			 | 
			
			
				+import cz.msebera.android.httpclient.entity.FileEntity; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				22
			 | 
			
			
				+import cz.msebera.android.httpclient.entity.mime.MultipartEntityBuilder; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				23
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				24
			 | 
			
			
				+/** 
			 | 
		
	
		
			
			| 
				
			 | 
			
				25
			 | 
			
			
				+ * Created by wkh237 on 2016/6/21. 
			 | 
		
	
		
			
			| 
				
			 | 
			
				26
			 | 
			
			
				+ */ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				27
			 | 
			
			
				+public class RNFetchBlobReq implements Runnable{ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				28
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				29
			 | 
			
			
				+    final String filePathPrefix = "RNFetchBlob-file://"; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				30
			 | 
			
			
				+    ReactApplicationContext ctx; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				31
			 | 
			
			
				+    RNFetchBlobConfig options; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				32
			 | 
			
			
				+    String taskId; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				33
			 | 
			
			
				+    String method; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				34
			 | 
			
			
				+    String url; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				35
			 | 
			
			
				+    String boundary; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				36
			 | 
			
			
				+    ReadableMap headers; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				37
			 | 
			
			
				+    Callback callback; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				+    HttpEntity entity; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				39
			 | 
			
			
				+    AsyncHttpClient req; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				40
			 | 
			
			
				+    String type; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				41
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				42
			 | 
			
			
				+    public RNFetchBlobReq(ReactApplicationContext ctx, ReadableMap options, String taskId, String method, String url, ReadableMap headers, String body, final Callback callback) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				43
			 | 
			
			
				+        this.ctx = ctx; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				44
			 | 
			
			
				+        this.method = method; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				45
			 | 
			
			
				+        this.options= new RNFetchBlobConfig(options); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				46
			 | 
			
			
				+        this.taskId = taskId; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				47
			 | 
			
			
				+        this.url = url; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				48
			 | 
			
			
				+        this.headers = headers; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				49
			 | 
			
			
				+        this.callback = callback; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				50
			 | 
			
			
				+        this.req = new AsyncHttpClient(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				51
			 | 
			
			
				+        if(body != null) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				52
			 | 
			
			
				+            type = "octet"; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				53
			 | 
			
			
				+            buildEntity(body); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				54
			 | 
			
			
				+        } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				55
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				56
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				57
			 | 
			
			
				+    public RNFetchBlobReq(ReactApplicationContext ctx, ReadableMap options, String taskId, String method, String url, ReadableMap headers, ReadableArray body, final Callback callback) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				58
			 | 
			
			
				+        this.ctx = ctx; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				59
			 | 
			
			
				+        this.method = method; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				60
			 | 
			
			
				+        this.options= new RNFetchBlobConfig(options); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				61
			 | 
			
			
				+        this.taskId = taskId; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				62
			 | 
			
			
				+        this.url = url; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				63
			 | 
			
			
				+        this.headers = headers; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				64
			 | 
			
			
				+        this.callback = callback; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				65
			 | 
			
			
				+        this.req = new AsyncHttpClient(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				66
			 | 
			
			
				+        if(body != null) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				67
			 | 
			
			
				+            type = "form"; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				68
			 | 
			
			
				+            buildFormEntity(body); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				69
			 | 
			
			
				+        } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				70
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				71
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				72
			 | 
			
			
				+    @Override 
			 | 
		
	
		
			
			| 
				
			 | 
			
				73
			 | 
			
			
				+    public void run() { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				74
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				75
			 | 
			
			
				+        try { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				76
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				77
			 | 
			
			
				+//            AsyncHttpClient req = new AsyncHttpClient(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				78
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				79
			 | 
			
			
				+            // use trusty SSL socket 
			 | 
		
	
		
			
			| 
				
			 | 
			
				80
			 | 
			
			
				+            if(this.options.trusty) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				81
			 | 
			
			
				+                KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				82
			 | 
			
			
				+                trustStore.load(null, null); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				83
			 | 
			
			
				+                MySSLSocketFactory sf = new MySSLSocketFactory(trustStore); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				84
			 | 
			
			
				+                sf.setHostnameVerifier(MySSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				85
			 | 
			
			
				+                req.setSSLSocketFactory(sf); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				86
			 | 
			
			
				+            } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				87
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				88
			 | 
			
			
				+            // set headers 
			 | 
		
	
		
			
			| 
				
			 | 
			
				89
			 | 
			
			
				+            if(headers != null) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				90
			 | 
			
			
				+                ReadableMapKeySetIterator it = headers.keySetIterator(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				91
			 | 
			
			
				+                while (it.hasNextKey()) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				92
			 | 
			
			
				+                    String key = it.nextKey(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				93
			 | 
			
			
				+                    req.addHeader(key, headers.getString(key)); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				94
			 | 
			
			
				+                } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				95
			 | 
			
			
				+            } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				96
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				97
			 | 
			
			
				+            if(type != null) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				98
			 | 
			
			
				+            { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				99
			 | 
			
			
				+                if(type == "octet") 
			 | 
		
	
		
			
			| 
				
			 | 
			
				100
			 | 
			
			
				+                    req.addHeader("Content-Type", "application/octet-stream"); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				101
			 | 
			
			
				+                else if(type == "form") 
			 | 
		
	
		
			
			| 
				
			 | 
			
				102
			 | 
			
			
				+                    req.addHeader("Content-Type", "multipart/form-data; charset=utf8; boundary="+boundary); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				103
			 | 
			
			
				+            } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				104
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				105
			 | 
			
			
				+            AsyncHttpResponseHandler handler; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				106
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				107
			 | 
			
			
				+            // create handler 
			 | 
		
	
		
			
			| 
				
			 | 
			
				108
			 | 
			
			
				+            if(options.fileCache || options.path != null) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				109
			 | 
			
			
				+                handler = new RNFetchBlobFileHandler(ctx, taskId, options, callback); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				110
			 | 
			
			
				+                // if path format invalid, throw error 
			 | 
		
	
		
			
			| 
				
			 | 
			
				111
			 | 
			
			
				+                if (!((RNFetchBlobFileHandler)handler).isValid) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				112
			 | 
			
			
				+                    callback.invoke("RNFetchBlob fetch error, configuration path `"+ options.path  +"` is not a valid path."); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				113
			 | 
			
			
				+                    return; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				114
			 | 
			
			
				+                } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				115
			 | 
			
			
				+            } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				116
			 | 
			
			
				+            else 
			 | 
		
	
		
			
			| 
				
			 | 
			
				117
			 | 
			
			
				+                handler = new RNFetchBlobBinaryHandler(this.ctx, taskId, callback); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				118
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				119
			 | 
			
			
				+            // send request 
			 | 
		
	
		
			
			| 
				
			 | 
			
				120
			 | 
			
			
				+            switch(method.toLowerCase()) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				121
			 | 
			
			
				+                case "get" : 
			 | 
		
	
		
			
			| 
				
			 | 
			
				122
			 | 
			
			
				+                    req.get(url, handler); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				123
			 | 
			
			
				+                    break; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				124
			 | 
			
			
				+                case "post" : 
			 | 
		
	
		
			
			| 
				
			 | 
			
				125
			 | 
			
			
				+                    if(this.type == null || this.type.equalsIgnoreCase("octet")) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				126
			 | 
			
			
				+                        req.post(ctx, url, entity, "application/octet-stream", handler); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				127
			 | 
			
			
				+                    else 
			 | 
		
	
		
			
			| 
				
			 | 
			
				128
			 | 
			
			
				+                        req.post(ctx, url, entity, "multipart/form-data", handler); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				129
			 | 
			
			
				+                    break; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				130
			 | 
			
			
				+                case "put" : 
			 | 
		
	
		
			
			| 
				
			 | 
			
				131
			 | 
			
			
				+                    if(this.type == null || this.type.equalsIgnoreCase("octet")) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				132
			 | 
			
			
				+                        req.post(ctx, url, entity, "application/octet-stream", handler); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				133
			 | 
			
			
				+                    else 
			 | 
		
	
		
			
			| 
				
			 | 
			
				134
			 | 
			
			
				+                        req.post(ctx, url, entity, "multipart/form-data", handler); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				135
			 | 
			
			
				+                    break; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				136
			 | 
			
			
				+                case "delete" : 
			 | 
		
	
		
			
			| 
				
			 | 
			
				137
			 | 
			
			
				+                    req.delete(url, handler); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				138
			 | 
			
			
				+                    break; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				139
			 | 
			
			
				+            } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				140
			 | 
			
			
				+        } catch(Exception error) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				141
			 | 
			
			
				+            callback.invoke( "RNFetchBlob serialize request data failed: " + error.getMessage() + error.getCause()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				142
			 | 
			
			
				+        } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				143
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				144
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				145
			 | 
			
			
				+    /** 
			 | 
		
	
		
			
			| 
				
			 | 
			
				146
			 | 
			
			
				+     * Build Mutipart body 
			 | 
		
	
		
			
			| 
				
			 | 
			
				147
			 | 
			
			
				+     * @param body  Body in array format 
			 | 
		
	
		
			
			| 
				
			 | 
			
				148
			 | 
			
			
				+     */ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				149
			 | 
			
			
				+    void buildFormEntity(ReadableArray body) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				150
			 | 
			
			
				+        if(body != null && (method.equalsIgnoreCase("post") || method.equalsIgnoreCase("put"))) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				151
			 | 
			
			
				+            Long tsLong = System.currentTimeMillis()/1000; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				152
			 | 
			
			
				+            String ts = tsLong.toString(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				153
			 | 
			
			
				+            boundary = "RNFetchBlob".concat(ts); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				154
			 | 
			
			
				+            MultipartEntityBuilder form = MultipartEntityBuilder.create(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				155
			 | 
			
			
				+            form.setBoundary(boundary); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				156
			 | 
			
			
				+            for( int i = 0; i< body.size(); i++) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				157
			 | 
			
			
				+                ReadableMap map = body.getMap(i); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				158
			 | 
			
			
				+                String name = map.getString("name"); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				159
			 | 
			
			
				+                if(!map.hasKey("data")) 
			 | 
		
	
		
			
			| 
				
			 | 
			
				160
			 | 
			
			
				+                    continue; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				161
			 | 
			
			
				+                String data = map.getString("data"); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				162
			 | 
			
			
				+                // file field 
			 | 
		
	
		
			
			| 
				
			 | 
			
				163
			 | 
			
			
				+                if(map.hasKey("filename")) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				164
			 | 
			
			
				+                    String filename = map.getString("filename"); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				165
			 | 
			
			
				+                    // upload from storage 
			 | 
		
	
		
			
			| 
				
			 | 
			
				166
			 | 
			
			
				+                    if(data.startsWith(filePathPrefix)) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				167
			 | 
			
			
				+                        File file = new File(data.substring(filePathPrefix.length())); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				168
			 | 
			
			
				+                        form.addBinaryBody(name, file, ContentType.APPLICATION_OCTET_STREAM, filename); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				169
			 | 
			
			
				+                    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				170
			 | 
			
			
				+                    // base64 embedded file content 
			 | 
		
	
		
			
			| 
				
			 | 
			
				171
			 | 
			
			
				+                    else { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				172
			 | 
			
			
				+                        form.addBinaryBody(name, Base64.decode(data, 0), ContentType.APPLICATION_OCTET_STREAM, filename); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				173
			 | 
			
			
				+                    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				174
			 | 
			
			
				+                } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				175
			 | 
			
			
				+                // data field 
			 | 
		
	
		
			
			| 
				
			 | 
			
				176
			 | 
			
			
				+                else { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				177
			 | 
			
			
				+                    form.addTextBody(name, map.getString("data")); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				178
			 | 
			
			
				+                } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				179
			 | 
			
			
				+            } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				180
			 | 
			
			
				+            entity = form.build(); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				181
			 | 
			
			
				+        } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				182
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				183
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				184
			 | 
			
			
				+    /** 
			 | 
		
	
		
			
			| 
				
			 | 
			
				185
			 | 
			
			
				+     * Build Octet-Stream body 
			 | 
		
	
		
			
			| 
				
			 | 
			
				186
			 | 
			
			
				+     * @param body  Body in string format 
			 | 
		
	
		
			
			| 
				
			 | 
			
				187
			 | 
			
			
				+     */ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				188
			 | 
			
			
				+    void buildEntity(String body) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				189
			 | 
			
			
				+        // set body for POST and PUT 
			 | 
		
	
		
			
			| 
				
			 | 
			
				190
			 | 
			
			
				+        if(body != null && (method.equalsIgnoreCase("post") || method.equalsIgnoreCase("put"))) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				191
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				192
			 | 
			
			
				+            byte [] blob; 
			 | 
		
	
		
			
			| 
				
			 | 
			
				193
			 | 
			
			
				+            // upload from storage 
			 | 
		
	
		
			
			| 
				
			 | 
			
				194
			 | 
			
			
				+            if(body.startsWith(filePathPrefix)) { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				195
			 | 
			
			
				+                String filePath = body.substring(filePathPrefix.length()); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				196
			 | 
			
			
				+                entity = new FileEntity(new File(filePath)); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				197
			 | 
			
			
				+            } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				198
			 | 
			
			
				+            else { 
			 | 
		
	
		
			
			| 
				
			 | 
			
				199
			 | 
			
			
				+                blob = Base64.decode(body, 0); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				200
			 | 
			
			
				+                entity = new ByteArrayEntity(blob); 
			 | 
		
	
		
			
			| 
				
			 | 
			
				201
			 | 
			
			
				+            } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				202
			 | 
			
			
				+        } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				203
			 | 
			
			
				+ 
			 | 
		
	
		
			
			| 
				
			 | 
			
				204
			 | 
			
			
				+    } 
			 | 
		
	
		
			
			| 
				
			 | 
			
				205
			 | 
			
			
				+} 
			 |