开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜