2011-11-30 45 views
0

我想上传图片&用不同的名字发送。用不同的名字上传文件

将图像发送成功,但与原来的名称:

httpPostuplod = new HttpPost(URL); 
MultipartEntity multiPart = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); 

for (int i = 0; i < imglist.size(); i++) {  
    System.out.println(imglist.get(i)); 
    File file = new File(imglist.get(i)); 

    // multiPart.addPart("IMG_"+Constants_Fix.postImgcount+".png", new FileBody(new File(imglist.get(i)))); 
    ContentBody cbFile = new FileBody(file, "image/png"); 

    multiPart.addPart("IMG_"+Constants_Fix.postImgcount+".png",cbFile); 

    Constants_Fix.postImgcount++; 
} 

httpPostuplod.setEntity(multiPart); 

HttpResponse resuplod = httpclient.execute(httpPostuplod); 

回答

0

/** * 产生的随机数不指定任何范围 */

Random rand = new Random(); 
      int numNoRange = rand.nextInt(); 
      String number = String.valueOf(numNoRange); 

File imageFile = new File(path,number+"img.jpg"); 

产生一个随机数和追加数到您的图像名称

+0

然后更改名称:文件名+号码 – jennifer

+0

忽略该代码..我只是把代码你要显示如何附加图像名称的数字 – jennifer

+0

数字的意思? – jennifer

相关问题