HTML5技术

html5上传图片(二)一解决部分手机拍照上传图片转向问题 - 大朋展翅(3)

字号+ 作者:H5之家 来源:H5之家 2016-08-06 10:00 我要评论( )

ProcessRequest(HttpContext context) 2 { String target = ; ]; ,target,sid); 7 string imgText = string .Empty; ])) 9 { ); 11 Response.End(); 12 } 13 14 Stream stream = new MemoryStream(); 15 string fil

ProcessRequest(HttpContext context) 2 { String target = ; ]; ,target,sid); 7 string imgText = string.Empty; ])) 9 { ); 11 Response.End(); 12 } 13 14 Stream stream = new MemoryStream(); 15 string fileName = string.Empty; 16 byte[] bArr = null; 17 if (context.Request.Files.Count > 0) 18 { 19 var file = context.Request.Files[0]; 20 fileName = file.FileName; 21 stream = file.InputStream; 22 bArr = new byte[stream.Length]; 23 stream.Read(bArr, 0, bArr.Length); 24 stream.Close(); 25 } 26 else { 27 imgText = HttpUtility.UrlDecode(imgText); ).Value; , , ); 30 if (imgText.Length % 4 > 0) 31 { ); 33 } 34 bArr=Convert.FromBase64String(imgText); ; 37 38 } 39 HttpWebRequest request = WebRequest.Create(target) as HttpWebRequest; 40 CookieContainer cookieContainer = new CookieContainer(); 41 request.CookieContainer = cookieContainer; 42 request.AllowAutoRedirect = true; ; , + context.Request.UrlReferrer.Host); , ); , ); , ); 48 request.Referer = context.Request.UrlReferrer.OriginalString; ); request.ContentType = + boundary; + boundary + ); + boundary + ); StringBuilder sbHeader = ,fileName)); 56 byte[] postHeaderBytes = Encoding.UTF8.GetBytes(sbHeader.ToString()); 57 58 Stream postStream = request.GetRequestStream(); 59 postStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length); 60 postStream.Write(postHeaderBytes, 0, postHeaderBytes.Length); 61 postStream.Write(bArr, 0, bArr.Length); 62 postStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length); 63 postStream.Close(); HttpWebResponse response = request.GetResponse() as HttpWebResponse; 66 SetCookie(response,context); } SetCookie(HttpWebResponse response, HttpContext context) 76 { 77 foreach (Cookie cookie in response.Cookies) 78 { )) 80 { 81 string result=string.Empty; )) 83 { ); 85 result = r.Match(cookie.Value).Value; 86 } 87 else { 88 result = cookie.Value; 89 } 90 context.Response.Write(result); 91 context.Response.End(); 92 } 93 94 } 95 }

View Code

      本次遇到的难题主要是解析base64字符串的问题,总是遇到"输入的不是有效的 Base-64 字符串,因为它包含非 Base-64 字符、两个以上的填充字"。经过反复的调整,终于实现了相应的功能。

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • HTML5 进阶系列:拖放 API 实现拖放排序 - _林鑫

    HTML5 进阶系列:拖放 API 实现拖放排序 - _林鑫

    2017-05-02 11:02

  • HTML5 进阶系列:indexedDB 数据库 - _林鑫

    HTML5 进阶系列:indexedDB 数据库 - _林鑫

    2017-04-27 14:02

  • HTML5 高级系列:web Storage - _林鑫

    HTML5 高级系列:web Storage - _林鑫

    2017-04-27 14:01

  • HTML5和CSS3 - 奔跑在起跑线佼佼者

    HTML5和CSS3 - 奔跑在起跑线佼佼者

    2017-04-20 13:00

网友点评