我需要收到一个HTTP Post Multipart,它只包含2个参数:
设置身体的正确方法是什么?我将使用Chrome REST控制台测试HTTP调用,所以我想知道正确的解决方案是为JSON参数和二进制文件设置"标签"键.
在服务器端我正在使用Resteasy 2.x,我将阅读这样的Multipart主体:
@POST
@Consumes("multipart/form-data")
public String postWithPhoto(MultipartFormDataInput multiPart) {
Map <String, List<InputPart>> params = multiPart.getFormDataMap();
String myJson = params.get("myJsonName").get(0).getBodyAsString();
InputPart imagePart = params.get("photo").get(0);
//do whatever I need to do with my json and my photo
}
Run Code Online (Sandbox Code Playgroud)
这是要走的路吗?使用标识特定内容处置的键"myJsonName"检索我的JSON字符串是否正确?有没有其他方法可以在一个HTTP多部分请求中接收这两个内容?
提前致谢
我想用这个JSON主体(包含图片)和Retrofit做一个PUT请求.我在Android下使用它:
{
"Request": {
"data": {
"Key": "keydata",
"param": {
"title": "Testingpostmultipartimageupload",
"photo": **"IMAGE BYTE DATA"**
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
有线索吗?
我正在尝试使用Retrofit库上传图像.这是我上传的方式:
请求代码:
@Multipart
@POST("/customerapp/{context}/{token}/passenger/passport/add/{passengerId}")
@Headers({
"Accept: application/xml",
"Accept-Encoding: gzip"
})
void UploadImage(
@Path("context") String context,
@Path("token") String token,
@Path("passengerId") String passengerId,
@Query("fileType") String fileType,
@Query("imageCategory") int imageCategory,
@Part("imageContent") TypedFile file,
Callback<VJSuccessResponse> callback
);
public static final String BASE_URL =
"http://webservicetest.abc.com/extranetServices/1.1";
RequestInterceptor requestInterceptor = new RequestInterceptor() {
@Override
public void intercept(RequestFacade request) {
Log.e("Retrofit Request Body", request.toString());
}
};
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint(BackendConstants.BASE_URL)
.setClient(new OkClient(new OkHttpClient()))
.setConverter(new SimpleXMLConverter())
.setLogLevel(RestAdapter.LogLevel.FULL)
.setRequestInterceptor(requestInterceptor)
.build();
REST_CLIENT = restAdapter.create(BackendAPI.class);
REST_CLIENT.UploadImage(
BackendConstants.CONTEXT,
StateObject.sSPManager.getStoredPersonalDetails().getToken(),
passengerId,
new …Run Code Online (Sandbox Code Playgroud)