4

写真やビデオを撮るためのAndroidアプリケーションを作成しています。画像をキャプチャした後、この画像を日付とテキストとともに Web サーバーに送信します。サーバー側では、この写真とビデオでアプリケーションを作成しています。撮影した画像はメモリーカードに保存されます。JSON を使用してテキスト付きの画像を送信するにはどうすればよいですか。また、ビデオを Web サーバーに送信したいと考えています。

4

3 に答える 3

1

マルチパート ポスト リクエストでこれを行うことができます:(この方法では、json を作成する必要はありません)

        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(serverURL);
        MultipartEntity postEntity = new MultipartEntity();
        File file = new File("Your File path on SD card");
        postEntity.addPart("fileupload", new FileBody(file, "image/jpeg"));
        postEntity.addPart("loginKey", new StringBody(""+loginKey));
        postEntity.addPart("message", new StringBody(message));
        postEntity.addPart("token", new StringBody(token));
        post.setEntity(postEntity);
        response = client.execute(post);

このmime4jライブラリを追加する必要があります。

于 2013-10-10T09:12:27.303 に答える
0

asynctask でこのコードを使用できます。

File file = new File("Your File path on SD card");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost("YourUrl");

MultipartEntity entity = new MultipartEntity();
entity.addPart("YourKey",new StringBody("Your Text"));
entity.addPart("File", new FileBody(file));
httpost.setEntity(entity);


HttpResponse response = httpclient.execute(httpost);
于 2013-10-10T09:13:56.007 に答える