我想在Multipart-Entity中发送带有文件路径的String []我得到link(我的代码太大了,不能发布,所以我发布参考链接)其中@rohit mandiwal代码适用于单个图像没有字符串[],但现在我已经发送了多个带有字符串[]
的图像该服务的我的服务器端代码就像那样
@RequestMapping(value = "/Images", method = RequestMethod.POST)
@ResponseBody
@ResponseStatus(value = HttpStatus.OK)
public ImageFilePath uploadFileImage(
@RequestParam("file") MultipartFile[] multipartFiles,@RequestParam("side") String[] sides)
throws Exception {
return AppointmentService.uploadFileImage(multipartFiles, sides);
}
但我无法通过更改上述代码将 String [] side 发送到该服务。 我的服务要求类似于
"Token:ulhas...@gmail.com:people:1460612590421:3f8eeae2f6d2a53c18117bca8952d018" -H "Content-Type:multipart/form-data" "myURL/appointment/myImages" -X POST -F file=@/home/ulhas/Desktop/desktopPdata/img_195753.jpg -F side=left -F file=@/home/ulhas/Desktop/desktopPdata/img_195753.jpg -F side=left
答案 0 :(得分:0)
试试这段代码..
private class webAsync extends AsyncTask<String, Integer, String> {
private ProgressDialog pb = null;
private HttpResponse httpResponse;
private HttpPost postRequest;
private HttpClient httpClient;
private HttpEntity httpEntity;
String Str_imagepath="path file";
@Override
protected String doInBackground(String... params) {
String APP_SERVICE_DOMAIN = null;
String mIncomingUrl = null;
APP_SERVICE_DOMAIN = "URL webservice";
mIncomingUrl = APP_SERVICE_DOMAIN;// add the field if any
System.out.println("@Incoming Request URL ==" + mIncomingUrl);
try {
HttpPost httppost = new HttpPost(mIncomingUrl);
MultipartEntity entity = new MultipartEntity();
File myFile = new File(Str_imagepath);
Log.e("TAG_FILE", "Exists1 " + myFile.exists());
FileBody fileBody = new FileBody(myFile);
if(myFile.exists()) {
entity.addPart("image", fileBody);
// webservice parameter for file
}
for (String mArray: mSelectedCategoryArray)
{
entity .addPart("ArrayID[]", new StringBody(mArray));
}
httppost.setEntity(entity);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse httpresponse = httpclient.execute(httppost);
if (httpresponse.getEntity() != null) {
String fileResponse = EntityUtils.toString(httpresponse
.getEntity());
System.out.println("@@............." + fileResponse);
return fileResponse;
}
} catch (Exception e) {
}
return null;
}
}