我想使用 C# Web 服务将图像上传到 IIS 服务器。我为此编写了 web 方法如下:
[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)
{
// return the error message if the operation fails
return ex.Message.ToString();
}
}
Web 方法将参数作为 byte[]。我已将 sdcard 图像转换为 byte[],但是当我将其作为 URL 参数传递时它不起作用。我还尝试通过转换 byte[]数组到 base64 strig 仍然无法正常工作。
谁能告诉我如何使用 C# Web 服务将图像上传到 IIS 服务器。
请您参考如下方法:
