image uploading from android application to server using c# web service
I want to upload image to IIS server using c# web service. I have written the web method for this as follows:
[WebMethod]
public string UploadFile(byte[] f, string fileName)
{
try
{
MemoryStream ms = new MemoryStream(f);
FileStream fs = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath
("~/TransientStorage/") +fileName, FileMode.Create);
ms.WriteTo(fs);
ms.Close();
fs.Close();
fs.Dispose();
return "OK";
}
catch (Exception ex)
{
// retu开发者_JS百科rn the error message if the operation fails
return ex.Message.ToString();
}
}
Here the web method is taking argument as byte[] .I have convert the sdcard image to byte[] but when i am passing it as an URL paramete it is not working .I have also tried by converting the byte[] array to base64 strig still it is not working.
Can any one tell me how to upload image to IIS server using c# web service.
You'll need to POST
it to the server, setting the content type and including the byte array as the body of the post.
See here for an example of doing it from C#
and here for an example for Android.
精彩评论