I’m writting an android app which has to send a picture on a wcf webservice.
My app can contact the web service and give it the picture.
But, size are differents and I can’t open the picture on the web service.
EDIT :By changing the webservice part I got the exact same size for both. But, still unable to open it.
Android part (file size 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());
}
Edit :
Webservice (file size 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();
}
You read the file in chunks but write only the last chunk:
So try like this: