将照片从Android应用程序发送到服务器端


Sending photo from Android application to server side

我即将编写服务器端应用程序(很可能是PHP,但JAVA也是可能的)和android客户端应用程序。我试图弄清楚什么是将照片从android应用程序发送到服务器并在服务器端接收的最佳方式。如果这有任何方法可以优化/串行化一次发送多个图片
请给我一些参考或提示
提前谢谢。

U可以为此使用HTTP post。获取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/