2011-11-30 51 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

相關問題