gpt4 book ai didi

android - 如何将图像数组从android添加到服务器

转载 作者:太空狗 更新时间:2023-10-29 16:21:08 25 4
gpt4 key购买 nike

在我的应用程序中,我想将图像数组添加到服务器

public void executeMultipartRequest(String eqname, String eqdesc,String CatId,String eqserial){
try{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");
String urlPath= "http://njjjjjbjjb.com/bbbbbbbb/interface/m.php?method=add";

System.out.println("URL Path is "+urlPath);

HttpPost postRequest = new HttpPost(urlPath);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("userid", new StringBody(FalconGearApp.getInstance().getUserId()));
reqEntity.addPart("sid", new StringBody(FalconGearApp.getInstance().getSessionId()));
reqEntity.addPart("categoryid",new StringBody( CatId));
reqEntity.addPart("eqname",new StringBody( eqname));
reqEntity.addPart("eqdescription",new StringBody( eqdesc));
reqEntity.addPart("eqserial", new StringBody(eqserial));
reqEntity.addPart("eqphoto", bab);
reqEntity.addPart("eqphoto", bab);
reqEntity.addPart("eqphoto", bab);

postRequest.setEntity(reqEntity);
HttpResponse response = httpClient.execute(postRequest);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
String sResponse;
StringBuilder s = new StringBuilder();
while ((sResponse = reader.readLine()) != null) {

s = s.append(sResponse);

}

System.out.println("Response is: " + s);



}catch(Exception e){
e.printStackTrace();


}



}

使用上面的代码我可以上传单个图像,但我想上传图像数组所以请帮助我如何上传图像数组,

最佳答案

试试这个:

reqEntity.addPart("eqphoto[0]", bab0);
reqEntity.addPart("eqphoto[1]", bab1);
reqEntity.addPart("eqphoto[2]", bab2);

关于android - 如何将图像数组从android添加到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14529301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com