![](/img/trans.png)
[英]Sending notification (few data) from PHP server side App to Android Client Side App
[英]Sending photo from Android application to server side
我將要編寫服務器端應用程序(最有可能是PHP,但也可能是JAVA)和android客戶端應用程序。 我試圖找出最好的方法是從Android應用程序向服務器發送照片並在服務器端接收照片的最佳方法。 而且,是否可以通過這種方式優化/序列化一次發送多張圖片?
請提供一些參考或提示。
提前致謝。
您可以使用HTTP發布。 獲取ByteArrayOutputStream並壓縮JPEG圖像,然后使用ByteArrayBody並使用HttpClient將其發布
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bm.compress(CompressFormat.JPEG, 75, bos);
byte[] data = bos.toByteArray();
HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost(
"http://10.0.2.2/cfc/iphoneWebservice.cfc?returnformat=json&method=testUpload");
ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");
// File file= new File("/mnt/sdcard/forest.png");
// FileBody bin = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("uploaded", bab);
reqEntity.addPart("photoCaption", new StringBody("sfsdfsdf"));
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);
}
您可以在此處找到相關代碼。 http://vikaskanani.wordpress.com/2011/01/11/android-upload-image-or-file-using-http-post-multi-part/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.