收藏
回答

小程序上传素材图片问题?

用的httpClient,相关代码如下

String result=null;
//文件名
String fileName = file.getName();
MultipartEntityBuilder mBuilder = MultipartEntityBuilder.create();
mBuilder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
mBuilder.addBinaryBody("media", file, ContentType.DEFAULT_BINARY, fileName);
HttpEntity he = mBuilder.build();
SSLContext context = getTrustAllSSLContext();
SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(context);
CloseableHttpClient client = HttpClients.custom().setSSLSocketFactory(factory).build();
try {
   HttpPost post = wxPost(url);
   post.setEntity(he);
   CloseableHttpResponse reponse = client.execute(post);
   try {
      HttpEntity entity = reponse.getEntity();
      result = EntityUtils.toString(entity);
      EntityUtils.consume(entity);
   } finally {
      reponse.close();
   }
} finally {
   client.close();
}
return result;

返回的是{"errcode":40005,"errmsg":"invalid file type hint: [iIdHwA05760016] rid: 5fb4ae20-29f4fcd2-69b1e7b1"}

回答关注问题邀请回答
收藏

1 个回答

  • Mr.Zhao
    Mr.Zhao
    2020-11-18

    2020-11-18
    有用 1
    回复 4
    • 刘运
      刘运
      2020-11-18
      文件格式有限制吗?我上传的好像是jpeg
      2020-11-18
      回复
    • Mr.Zhao
      Mr.Zhao
      2020-11-18回复刘运
      连图片后缀都确定不了,不出问题才怪
      2020-11-18
      回复
    • 刘运
      刘运
      2020-11-18回复Mr.Zhao
      我再找找原因
      2020-11-18
      回复
    • 刘运
      刘运
      2020-11-18回复Mr.Zhao
      谢谢了,找到原因了。我去文件服务器取文件的方法错了,文件一直是空的。
      2020-11-18
      回复
登录 后发表内容
问题标签