问题描述
- app 调用webservice的图片上传接口报错
-
以下为c#写的图片上传接口,图片是在app转为base64的;而当在服务上测试时是可以上传,即下图的位置
可是在app调用该接口时却出错,这是为什么,困扰了多天了。请大神帮忙哈public JObject UploadPicture(string jsonString)
{
JToken Picture;
JObject jobject = JObject.Parse(jsonString);
Picture = jobject.GetValue("Picture");
JObject jObj = new JObject();
int re = 0;
string imgStr = Picture.ToString(),pictureAddress;
string picture = DateTime.Now.Ticks.ToString() + ".jpg", filePath;
filePath = "~/Resources/images/" + picture;//将base64图片解析出来 if (imgStr == "") { re = 0; } else { byte[] LogoBytes = Convert.FromBase64String(imgStr);//base64转二进制 MemoryStream stream = new MemoryStream(LogoBytes);//二进制转流 Image img1 = Image.FromStream(stream);//流转image if (Directory.Exists(Server.MapPath("~/Resources/images")) == false) { Directory.CreateDirectory(Server.MapPath("~/Resources/images")); } string add = Server.MapPath(filePath);//地址 Bitmap server = new Bitmap(img1); try { server.Save(add); re = 1; } catch { re = 0; } stream.Dispose(); server.Dispose(); img1.Dispose(); } jObj.Add(new JProperty("re", re)); if (re == 1) { pictureAddress = "/wd_test/Resources/images/" + picture; jObj.Add(new JProperty("pictureAddress", pictureAddress)); } return jObj;
}
时间: 2024-11-01 10:08:24