上传图片
Posted lslnn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了上传图片相关的知识,希望对你有一定的参考价值。
//随手拍图片
string url = "http://localhost:8099/OpenAPI/UpLoadPhotographImage";
string imgresult = "";
List<string> imglist = new List<string>();
foreach (imglist item in img)
{
string img1 = item.imgurl;
if (img1 != null && img1.Length > 0)
{
WebRequest request = System.Net.WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
Stream reqStream = request.GetRequestStream();
string img1base64 = System.Web.HttpUtility.UrlEncode(img1);
Encoding encoding = Encoding.GetEncoding("utf-8");
byte[] postdata = encoding.GetBytes("img1base64=" + img1base64);
reqStream.Write(postdata, 0, postdata.Length);
reqStream.Close();
HttpWebResponse myResponse = (HttpWebResponse) request.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.GetEncoding("gb2312"));
imgresult = reader.ReadToEnd();//得到结果
imglist.Add(imgresult);
}
}
Service_Photoes pEntity = new Service_Photoes();
if (imglist.Count > 0)
{
pEntity.ServiceOrderId = OrderCode;
pEntity.ImageUrl = imglist[0];
pEntity.FileName = "服务";
pEntity.ThumbnailUrl100 = imglist[0];
pEntity.ThumbnailUrl160 = imglist[0];
pEntity.ThumbnailUrl180 = imglist[0];
pEntity.ThumbnailUrl220 = imglist[0];
pEntity.ThumbnailUrl310 = imglist[0];
pEntity.ThumbnailUrl40 = imglist[0];
pEntity.ThumbnailUrl410 = imglist[0];
pEntity.ThumbnailUrl60 = imglist[0];
//pEntity.ImageUrl2 = imglist.Count > 1 ? imglist[1] : "";
//pEntity.ImageUrl3 = imglist.Count > 2 ? imglist[2] : "";
//pEntity.ImageUrl4 = imglist.Count > 3 ? imglist[3] : "";
//pEntity.ImageUrl5 = imglist.Count > 4 ? imglist[4] : "";
}
Service_OrderBll orderBll = new Service_OrderBll();
Service_PhotoesBll photoesBll = new Service_PhotoesBll();
bool bRet = orderBll.SubmitService(entity);
if (pEntity.ImageUrl != "")
{
photoesBll.SubmitPhotograph(pEntity);
}
以上是关于上传图片的主要内容,如果未能解决你的问题,请参考以下文章