18
18
19
19
package com .loopj .android .http ;
20
20
21
- import java .io .ByteArrayInputStream ;
21
+ import java .io .InputStream ;
22
22
import java .io .File ;
23
23
import java .io .UnsupportedEncodingException ;
24
24
import java .util .LinkedList ;
@@ -89,7 +89,7 @@ public void put(String key, String value){
89
89
* @param key the key name for the new param.
90
90
* @param filedata the file contents to add.
91
91
*/
92
- public void put (String key , ByteArrayInputStream filedata ) {
92
+ public void put (String key , InputStream filedata ) {
93
93
put (key , filedata , null , null );
94
94
}
95
95
@@ -99,7 +99,7 @@ public void put(String key, ByteArrayInputStream filedata) {
99
99
* @param filedata the file contents to add.
100
100
* @param filename the name of the file.
101
101
*/
102
- public void put (String key , ByteArrayInputStream filedata , String filename ) {
102
+ public void put (String key , InputStream filedata , String filename ) {
103
103
put (key , filedata , filename , null );
104
104
}
105
105
@@ -110,7 +110,7 @@ public void put(String key, ByteArrayInputStream filedata, String filename) {
110
110
* @param filename the name of the file.
111
111
* @param contentType the content type of the file, eg. application/json
112
112
*/
113
- public void put (String key , ByteArrayInputStream filedata , String filename , String contentType ) {
113
+ public void put (String key , InputStream filedata , String filename , String contentType ) {
114
114
if (key != null && filedata != null ) {
115
115
fileParams .put (key , new FileWrapper (filedata , filename , contentType ));
116
116
}
@@ -171,16 +171,11 @@ HttpEntity getEntity() {
171
171
// Add file params
172
172
for (ConcurrentHashMap .Entry <String , FileWrapper > entry : fileParams .entrySet ()) {
173
173
FileWrapper file = entry .getValue ();
174
- if (file .bytes != null ) {
175
- String filename = file .filename ;
176
- if (filename == null ) {
177
- filename = "nofilename" ;
178
- }
179
-
174
+ if (file .inputStream != null ) {
180
175
if (file .contentType != null ) {
181
- multipartEntity .addPart (entry .getKey (), filename , file .bytes , file .contentType );
176
+ multipartEntity .addPart (entry .getKey (), file . getFileName () , file .inputStream , file .contentType );
182
177
} else {
183
- multipartEntity .addPart (entry .getKey (), filename , file .bytes );
178
+ multipartEntity .addPart (entry .getKey (), file . getFileName () , file .inputStream );
184
179
}
185
180
}
186
181
}
@@ -213,14 +208,22 @@ private List<BasicNameValuePair> getParamsList() {
213
208
}
214
209
215
210
private static class FileWrapper {
216
- public ByteArrayInputStream bytes ;
217
- public String filename ;
211
+ public InputStream inputStream ;
212
+ public String fileName ;
218
213
public String contentType ;
219
214
220
- public FileWrapper (ByteArrayInputStream bytes , String filename , String contentType ) {
221
- this .bytes = bytes ;
222
- this .filename = filename ;
215
+ public FileWrapper (InputStream inputStream , String fileName , String contentType ) {
216
+ this .inputStream = inputStream ;
217
+ this .fileName = fileName ;
223
218
this .contentType = contentType ;
224
219
}
220
+
221
+ public String getFileName () {
222
+ if (fileName != null ) {
223
+ return fileName ;
224
+ } else {
225
+ return "nofilename" ;
226
+ }
227
+ }
225
228
}
226
229
}
0 commit comments