我想上传一些图片说5.我不想将其转换为字节数组。我想将每个图像转换为FILE并添加到数组,然后将数组发送到服务器。在此之前,任何人都可以帮助我。
答案 0 :(得分:0)
尝试此代码和此库添加httpmime-4.1-beta1.jar:
字符串网址="您的网址";
HttpClient client = new DefaultHttpClient();
client.getParams().setParameter(
CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost postMethod = new HttpPost(url);
MultipartEntity entity = new MultipartEntity();
entity.addPart("fname", new StringBody("xyz"));
try {
File file1 = new File("Your image Path");
FileBody bin1 = new FileBody(file1, "images/jpeg");
entity.addPart("file", bin1);
File file2 = new File("Your image Path");
FileBody bin2 = new FileBody(file2, "images/jpeg");
entity.addPart("file", bin2);
File file3 = new File("Your image Path");
FileBody bin3 = new FileBody(file3, "images/jpeg");
entity.addPart("file", bin3);
postMethod.setEntity(entity);
HttpResponse response;
response = client.execute(postMethod);
String result = EntityUtils.toString(response.getEntity());
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}