Skip to content

Commit 7f81988

Browse files
committed
update RequestParams
1 parent 52abf6c commit 7f81988

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

library/src/com/lidroid/xutils/http/RequestParams.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,18 +220,32 @@ public void addBodyParameter(String key, File file, String mimeType, String char
220220
fileParams.put(key, new FileBody(file, mimeType, charset));
221221
}
222222

223+
public void addBodyParameter(String key, File file, String fileName, String mimeType, String charset) {
224+
if (fileParams == null) {
225+
fileParams = new HashMap<String, ContentBody>();
226+
}
227+
fileParams.put(key, new FileBody(file, fileName, mimeType, charset));
228+
}
229+
230+
public void addBodyParameter(String key, InputStream stream, long length) {
231+
if (fileParams == null) {
232+
fileParams = new HashMap<String, ContentBody>();
233+
}
234+
fileParams.put(key, new InputStreamBody(stream, length));
235+
}
236+
223237
public void addBodyParameter(String key, InputStream stream, long length, String fileName) {
224238
if (fileParams == null) {
225239
fileParams = new HashMap<String, ContentBody>();
226240
}
227241
fileParams.put(key, new InputStreamBody(stream, length, fileName));
228242
}
229243

230-
public void addBodyParameter(String key, InputStream stream, long length, String mimeType, String fileName) {
244+
public void addBodyParameter(String key, InputStream stream, long length, String fileName, String mimeType) {
231245
if (fileParams == null) {
232246
fileParams = new HashMap<String, ContentBody>();
233247
}
234-
fileParams.put(key, new InputStreamBody(stream, length, mimeType, fileName));
248+
fileParams.put(key, new InputStreamBody(stream, length, fileName, mimeType));
235249
}
236250

237251
public void setBodyEntity(HttpEntity bodyEntity) {

library/src/com/lidroid/xutils/http/client/multipart/content/FileBody.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,11 @@ public FileBody(final File file,
4141
throw new IllegalArgumentException("File may not be null");
4242
}
4343
this.file = file;
44-
if (filename != null)
44+
if (filename != null) {
4545
this.filename = filename;
46-
else
46+
} else {
4747
this.filename = file.getName();
48+
}
4849
this.charset = charset;
4950
}
5051

@@ -58,11 +59,11 @@ public FileBody(final File file,
5859
}
5960

6061
public FileBody(final File file, final String mimeType) {
61-
this(file, mimeType, null);
62+
this(file, null, mimeType, null);
6263
}
6364

6465
public FileBody(final File file) {
65-
this(file, "application/octet-stream");
66+
this(file, null, "application/octet-stream", null);
6667
}
6768

6869
public InputStream getInputStream() throws IOException {

library/src/com/lidroid/xutils/http/client/multipart/content/InputStreamBody.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class InputStreamBody extends AbstractContentBody {
3232
private final String filename;
3333
private long length;
3434

35-
public InputStreamBody(final InputStream in, long length, final String mimeType, final String filename) {
35+
public InputStreamBody(final InputStream in, long length, final String filename, final String mimeType) {
3636
super(mimeType);
3737
if (in == null) {
3838
throw new IllegalArgumentException("Input stream may not be null");
@@ -43,11 +43,11 @@ public InputStreamBody(final InputStream in, long length, final String mimeType,
4343
}
4444

4545
public InputStreamBody(final InputStream in, long length, final String filename) {
46-
this(in, length, "application/octet-stream", filename);
46+
this(in, length, filename, "application/octet-stream");
4747
}
4848

4949
public InputStreamBody(final InputStream in, long length) {
50-
this(in, length, "application/octet-stream", "no_name");
50+
this(in, length, "no_name", "application/octet-stream");
5151
}
5252

5353
public InputStream getInputStream() {

0 commit comments

Comments
 (0)