合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
C#示例参考: ```C# //文件名称:upload_cross_domain.ashx <%@ WebHandler Language="C#" Class="data" %> using System; using System.Web; using System.IO; public class data : IHttpHandler { public void ProcessRequest (HttpContext context) { //设置文件类型和编码类型 context.Response.ContentType = "text/html"; context.Response.Charset = "utf-8"; //获取web前端 wangEditor_uploadImg_assist.html 页面的url地址 string assistUrl = "http://localhost:8080/wangEditor_uploadImg_assist.html"; //取得文件对象 HttpPostedFile file = context.Request.Files[0]; //HttpPostedFile file = context.Request.Files["wangEditor_uploadImg"]; if (file == null) { string iframeSrc = assistUrl + "#" + "未成功获取文件,上传失败"; string result = "<iframe src=\"" + iframeSrc + "\"></iframe>"; context.Response.Write(result); context.Response.End(); return; } else { //验证通过了,最后保存文件 string path = context.Server.MapPath("~/uploadedFiles/"); string originalFileName = file.FileName; string fileExtension = originalFileName.Substring(originalFileName.LastIndexOf('.'), originalFileName.Length - originalFileName.LastIndexOf('.')); string currentFileName = (new Random()).Next() + fileExtension; //文件名中不要带中文,否则会出错 //生成文件路径 string imagePath = path + currentFileName; //保存文件 file.SaveAs(imagePath); //保存文件之后,要告诉web前端上传已经成功了 //获取图片的url string imgUrl = "http://localhost:8080/uploadedFiles/" + currentFileName; string iframeSrc = assistUrl + "#" + "ok|" + imgUrl; string result = "<iframe src=\"" + iframeSrc + "\"></iframe>"; context.Response.Write(result); context.Response.End(); return; } } public bool IsReusable { get { return false; } } } ```