From 657edad784077d509d8f9dfcc3b1c173523a37bf Mon Sep 17 00:00:00 2001 From: liyi Date: Thu, 10 Mar 2016 12:14:09 +0800 Subject: [PATCH] =?UTF-8?q?MediaAPI=20bug=20=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.txt | 7 ++++++- pom.xml | 2 +- src/main/java/weixin/popular/api/MediaAPI.java | 10 ++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/changelog.txt b/changelog.txt index 361f8791..37acc9d9 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,7 +2,12 @@ WEIXIN-POPULAR CHANGELOG =========================== https://github.com/liyiorg/weixin-popular -Changes in version 2.6.1 (2016-03-) +Changes in version 2.6.2 (2016-03-10) +------------------------------------- +* weixin.popular.api.MediaAPI bug 修复 + + +Changes in version 2.6.1 (2016-03-01) ------------------------------------- * MessageAPI 添加模板消息管理接口 * QrcodeAPI 添加永久二维码 字符串场景值接口 diff --git a/pom.xml b/pom.xml index eaaf4f2c..3ad4b33d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 weixin weixin-popular - 2.6.1-RELEASE + 2.6.2-RELEASE https://github.com/liyiorg/weixin-popular diff --git a/src/main/java/weixin/popular/api/MediaAPI.java b/src/main/java/weixin/popular/api/MediaAPI.java index 0c2da951..45080c93 100644 --- a/src/main/java/weixin/popular/api/MediaAPI.java +++ b/src/main/java/weixin/popular/api/MediaAPI.java @@ -181,9 +181,15 @@ public static UploadimgResult mediaUploadimg(String access_token,File media){ */ public static UploadimgResult mediaUploadimg(String access_token,InputStream inputStream){ HttpPost httpPost = new HttpPost(BASE_URI+"/cgi-bin/media/uploadimg"); - InputStreamBody inputStreamBody = new InputStreamBody(inputStream, ContentType.MULTIPART_FORM_DATA, UUID.randomUUID().toString()+".jpg"); + //InputStreamBody inputStreamBody = new InputStreamBody(inputStream, ContentType.DEFAULT_BINARY, UUID.randomUUID().toString()+".jpg"); + byte[] data = null; + try { + data = StreamUtils.copyToByteArray(inputStream); + } catch (IOException e) { + e.printStackTrace(); + } HttpEntity reqEntity = MultipartEntityBuilder.create() - .addPart("media",inputStreamBody) + .addBinaryBody("media",data,ContentType.DEFAULT_BINARY,"temp.jpg") .addTextBody(getATPN(), access_token) .build(); httpPost.setEntity(reqEntity);