【发布时间】:2023-03-07 04:41:02
【问题描述】:
我需要使用 phonegaps Camera and File Transfer API 将图像上传到网络服务。
例如,在Webservice上有:
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public string SaveImage(string imageData, string filename)
{
string success = "Nothing";
try
{
string filename = "text.png";
if (!System.IO.Directory.Exists(HttpContext.Current.Server.MapPath("~/devimg")))
{
System.IO.Directory.CreateDirectory(HttpContext.Current.Server.MapPath("~/devimg/"));
}
string path = HttpContext.Current.Server.MapPath("~/devimg/").ToString();
byte[] imgByte = Convert.FromBase64String(imageData);
using (var imgStream = new MemoryStream(imgByte, true))
{
Bitmap img = new Bitmap(imgStream);
Image i = (Image)img;
i.Save(path + "" + filename, ImageFormat.Png);
success = "Image created!!";
}
}
catch (Exception e)
{
success = e.ToString();
}
return success;
}
在应用中有:
navigator.camera.getPicture( function( imgdata ){
//Base 64 encoded image file or whatever
}, CameraError , {
quality: 50,
destinationType: navigator.camera.DestinationType.DATA_URL,
sourceType: navigator.camera.PictureSourceType.CAMERA,
encodingType: navigator.camera.EncodingType.JPEG,
saveToPhotoAlbum: true
});
我拥有的当前网络服务允许将 Base 64 编码的图像传递给它,然后它将创建图像并使用给定的文件名保存它。但如果我尝试从 phonegap 应用程序访问网络服务,它就不起作用。
我尝试通过 ajax 访问 web 服务,但一直收到一堆错误。有没有更好的方法将图片上传到服务器?
【问题讨论】:
-
通过将
添加到我的网络配置中来修复 Http_Status 500。