修复InputStreamBody下无法获取长度的问题
This commit is contained in:
parent
9b67fbb1bb
commit
d820d3d18b
@ -39,6 +39,7 @@ public class InputStreamBody extends AbstractContentBody {
|
|||||||
|
|
||||||
private final InputStream in;
|
private final InputStream in;
|
||||||
private final String filename;
|
private final String filename;
|
||||||
|
private int contentLength;
|
||||||
|
|
||||||
public InputStreamBody(final InputStream in, final String mimeType,
|
public InputStreamBody(final InputStream in, final String mimeType,
|
||||||
final String filename) {
|
final String filename) {
|
||||||
@ -67,6 +68,7 @@ public class InputStreamBody extends AbstractContentBody {
|
|||||||
int l;
|
int l;
|
||||||
while ((l = this.in.read(tmp)) != -1) {
|
while ((l = this.in.read(tmp)) != -1) {
|
||||||
out.write(tmp, 0, l);
|
out.write(tmp, 0, l);
|
||||||
|
contentLength += l;
|
||||||
}
|
}
|
||||||
out.flush();
|
out.flush();
|
||||||
} finally {
|
} finally {
|
||||||
@ -83,12 +85,7 @@ public class InputStreamBody extends AbstractContentBody {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public long getContentLength() {
|
public long getContentLength() {
|
||||||
try {
|
return contentLength;
|
||||||
return in.available();
|
|
||||||
} catch (IOException e) {
|
|
||||||
;
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFilename() {
|
public String getFilename() {
|
||||||
|
|||||||
@ -207,7 +207,7 @@ public class MediaApi extends MpApi {
|
|||||||
String media_upload_uri = getRequestUri("media_upload_uri");
|
String media_upload_uri = getRequestUri("media_upload_uri");
|
||||||
response = weixinExecutor.post(String.format(media_upload_uri,
|
response = weixinExecutor.post(String.format(media_upload_uri,
|
||||||
token.getAccessToken(), mediaType.name()),
|
token.getAccessToken(), mediaType.name()),
|
||||||
new FormBodyPart("media", new ByteArrayBody(content, mediaType
|
new FormBodyPart("media", new InputStreamBody(new ByteArrayInputStream(content), mediaType
|
||||||
.getContentType().getMimeType(),
|
.getContentType().getMimeType(),
|
||||||
fileName)));
|
fileName)));
|
||||||
JSONObject obj = response.getAsJson();
|
JSONObject obj = response.getAsJson();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user