0

wcfWebサービスで画像を送信する必要があるAndroidアプリを作成しています。私のアプリはWebサービスに接続して、画像を提供できます。ただし、サイズが異なり、Webサービスで画像を開くことができません。

編集:Webサービスの部分を変更することで、両方でまったく同じサイズになりました。しかし、それでも開くことができません。

Androidパーツ(ファイルサイズ20ko):

File img;
try {
        Log.i("image", "get file");
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url);
        Log.i("call", "end build");

        MultipartEntity entity = new MultipartEntity();
        entity.addPart("data", new FileBody(f));

        httppost.setEntity(entity);
        Log.i("call", "call");
        HttpResponse response = httpclient.execute(httppost);
        Log.i("call", "After");

    }
catch (Exception e) {
    Log.i("error cal image", e.toString());
}

編集:Webサービス(ファイルサイズ20ko):

[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "picture")]
public void UploadPicture(Stream image)
{
     var ms = new MemoryStream();
        image.CopyTo(ms);
        var streamBytes = ms.ToArray();
        FileStream f = new FileStream("C:\\appicture.jpg", FileMode.OpenOrCreate);
        f.Write(streamBytes, 0, streamBytes.Length);
        f.Close();
        ms.Close();
        image.Close();


}
4

1 に答える 1

1

ファイルをチャンクで読み取りますが、最後のチャンクのみを書き込みます。

// following line is called once, should be called after each read
fileToupload.Write(bytearray, 0, bytearray.Length); 

したがって、次のようにしてみてください。

/*...*/
do
{
    bytesRead = image.Read(bytearray, 0, bytearray.Length);
    totalBytesRead += bytesRead;
    fileToupload.Write(bytearray, 0, bytesRead);
} while (bytesRead > 0);

fileToupload.Close();
fileToupload.Dispose();
/*...*/
于 2012-06-26T13:57:27.753 に答える