mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 18:46:10 +08:00 
			
		
		
		
	修复重构素材上传处理代码
This commit is contained in:
		| @ -30,11 +30,15 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri | ||||
|       httpPost.setConfig(response); | ||||
|     } | ||||
|  | ||||
|     if (material != null) { | ||||
|     if (material == null) { | ||||
|       throw new WxErrorException(WxError.newBuilder().setErrorMsg("非法请求,material参数为空").build()); | ||||
|     } | ||||
|  | ||||
|     File file = material.getFile(); | ||||
|     if (file == null || !file.exists()) { | ||||
|       throw new FileNotFoundException(); | ||||
|     } | ||||
|      | ||||
|     MultipartEntityBuilder multipartEntityBuilder = MultipartEntityBuilder.create(); | ||||
|     multipartEntityBuilder | ||||
|         .addBinaryBody("media", file) | ||||
| @ -43,9 +47,9 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri | ||||
|     if (material.getForm() != null) { | ||||
|       multipartEntityBuilder.addTextBody("description", WxGsonBuilder.create().toJson(form)); | ||||
|     } | ||||
|      | ||||
|     httpPost.setEntity(multipartEntityBuilder.build()); | ||||
|     httpPost.setHeader("Content-Type", ContentType.MULTIPART_FORM_DATA.toString()); | ||||
|     } | ||||
|  | ||||
|     try (CloseableHttpResponse response = httpclient.execute(httpPost)) { | ||||
|       String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response); | ||||
| @ -55,7 +59,7 @@ public class MaterialUploadRequestExecutor implements RequestExecutor<WxMpMateri | ||||
|       } else { | ||||
|         return WxMpMaterialUploadResult.fromJson(responseContent); | ||||
|       } | ||||
|     }finally { | ||||
|     } finally { | ||||
|       httpPost.releaseConnection(); | ||||
|     } | ||||
|   } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 BinaryWang
					BinaryWang