0
点赞
收藏
分享

微信扫一扫

集成第三方接口上传文件

cwq聖泉寒江2020 2022-03-30 阅读 86
java
一、上传文件到服务端
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String UploadFile(
  		@ApiParam("文件上传对象") MultipartFormDataInput input){}
二、调用第三方接口上传
public String UploadFile(MultipartFormDataInput artifactInput) throws Exception {
	Map<String, List<InputPart>> importForm = artifactInput.getFormDataMap();
	List<InputPart> inputParts = null == importForm ? null : importForm.get("input");
	//判断inputParts是否成功取到了值
	if (inputParts.isEmpty()) {
		throw new Exception();
	}
	InputPart inputPart = inputParts.get(0);
	InputStream inputStream = inputPart.getBody(InputStream.class, null);
	HttpClient httpClient = new HttpClient("url").method(HttpClient.PUT);
	Response response = httpClient.request(inputStream, 0);
	inputStream.close();
	return response.getBody();
}
举报

相关推荐

0 条评论