java服务端使用jersey进行图片上传
public static String uploadFileChatPost(String filePath,Map map,String endUri) throws IOException{
String code = null;
// File file = new File(filePath);
// JSONObject jsonObject = JSONObject.fromObject(file);
String file = "file="+readFileContent(filePath);
Client client=ClientBuilder.newClient();
WebTarget target = client.target(UrlNameConstants.BASEURLHEAD);
String restToken = getTokenFromRedis();
Response result = target.path(UrlNameConstants.BASEURL+endUri)
// .request(MediaType.MULTIPART_FORM_DATA_TYPE)
.request(MediaType.APPLICATION_JSON_TYPE)
.header("restrict-access",true)
.header("Authorization","Bearer "+restToken)
.accept(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.entity(file,MediaType.MULTIPART_FORM_DATA_TYPE));
System.out.println(result.toString());
code = result.readEntity(String.class);
System.out.println(code.toString());
return code;
}
图片上传,这个访问的post里面 我应该怎样填写 ,因为现今代码进行访问restful接口的时候返回的是空指针
String code = null;
// File file = new File(filePath);
// JSONObject jsonObject = JSONObject.fromObject(file);
String file = "file="+readFileContent(filePath);
Client client=ClientBuilder.newClient();
WebTarget target = client.target(UrlNameConstants.BASEURLHEAD);
String restToken = getTokenFromRedis();
Response result = target.path(UrlNameConstants.BASEURL+endUri)
// .request(MediaType.MULTIPART_FORM_DATA_TYPE)
.request(MediaType.APPLICATION_JSON_TYPE)
.header("restrict-access",true)
.header("Authorization","Bearer "+restToken)
.accept(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.entity(file,MediaType.MULTIPART_FORM_DATA_TYPE));
System.out.println(result.toString());
code = result.readEntity(String.class);
System.out.println(code.toString());
return code;
}
图片上传,这个访问的post里面 我应该怎样填写 ,因为现今代码进行访问restful接口的时候返回的是空指针
没有找到相关结果
已邀请:
0 个回复