我正在製作一個android應用程序,我正在從/mnt/sdcard/DCIM/Camera/IMG_20110922_124932.jpg發送圖像到服務器,以便通過多部分請求進行操作..任何人都可以幫我解決.... 任何幫助將不勝感激.. 謝謝..使用多部分條目從SD卡發送圖像到服務器
0
A
回答
0
下面是一個多後的一個簡單的例子,我用它來將圖像發送到服務器:
public void MultipartPost(){
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(url);
//Set Credentials
String auth = User + ":" + Pass;
byte[] bytes = auth.getBytes();
postRequest.setHeader("Authorization", "Basic " + new String(Base64.encodeBytes(bytes)));
try {
MultipartEntity mpC = new MultipartEntity();
//Create stringbody for the filename
StringBody sbPicID = new StringBody("123.jpg");
//get a file reference from the image on the SD card
File fle = new File("full path to the file");
//create a filebody from the file
FileBody fb = new FileBody(fle);
//Add the file name and filebody to the Multipart Entitiy
mpC.addPart("myImage", sbPicID);
mpC.addPart("myImage", fb);
//Set the entitiy of the post request to your Multipart
postRequest.setEntity(mpC);
HttpResponse res;
//execute the post request
Log.d(TAG,"Starting Send...");
res = httpClient.execute(postRequest);
Log.d(TAG, res.getStatusLine().getReasonPhrase());
Log.d(TAG, res.getStatusLine().getStatusCode());
res.getEntity().getContent().close();
Log.d(TAG,"After Close");
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
}
0
見接受的答案我上週回答的[這個問題] [1]。它與上面的答案非常相似,但也包含一些示例PHP代碼來獲取圖像。
相關問題
- 1. 將圖像發送到服務器的多部分iphone
- 2. 將選定的圖像從SD卡上傳到php服務器
- 3. 從SD卡上傳圖像到燈服務器
- 4. 如何將YUV圖像的一部分發送到服務器?
- 5. 如何從android發送100多個圖像到web服務器?
- 6. 從服務器發送彩色圖像
- 7. 從服務器下載圖像並保存在SD卡
- 8. XCode將圖像發送到服務器
- 9. 圖像發送問題到服務器
- 10. 發送圖像到MySQL服務器
- 11. 發送圖像到服務器?
- 12. Android將圖像發送到服務器
- 13. 發送圖像到服務器Ajax
- 14. 發送jpg圖像到服務器(json)
- 15. Ajax將圖像發送到服務器
- 16. 如何發送圖像到服務器
- 17. 發送圖像到服務器
- 18. 從IOS發送映像到服務器
- 19. 如何發送多個圖像到服務器使用MultipartEntity從android
- 20. 我想使用圖像url將圖像從java服務器發送到android
- 21. 圖像從SD卡到圖庫視圖
- 22. 如何從SD卡中選擇圖像文件,然後如何將其發送到服務器?
- 23. 使用SOAP將圖像從圖庫發送到Web服務
- 24. 從android分頁器保存圖像到sd卡
- 25. 如何從Android SD卡上傳圖片到Django服務器?
- 26. 使用Glide從SD卡加載圖像
- 27. 從應用程序發送圖像到網絡服務器
- 28. 從服務器發送圖像到Android應用程序
- 29. 電報從外部服務器發送圖像
- 30. 如何將圖像從SD卡上傳到服務器上的文件夾
感謝您的回答,但我必須做更多的搜索 – Aditya1510