我有一个Flex应用程序,它在我们的网络服务器上调用.aspx页面,该页面构建一个PDF或Excel文件.现在,我使用navigateToURL()来调用文件,这在成功构建输出文件时工作正常.但是,如果出现错误或超时,则无法在Flash影片中知道这一点.
我正在尝试使用URLLoader,以便我可以侦听HTTP状态代码,并知道何时加载完成,但是,URLLoader只返回位图数据,没有提示用户打开或保存输出文件.反正有没有这样做?
以下是我的ActionScript代码的两个版本:
private function buildFile():void { var variables:URLVariables = new URLVariables(); variables.rptName = "report1"; variables.rptFormat = "PDF"; var request:URLRequest = new URLRequest(); request.url = "/buildFile.aspx"; request.method = URLRequestMethod.POST; request.data = variables; var loader:URLLoader = new URLLoader(); loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusHandler); loader.load(request); } private function buildFile():void { var variables:URLVariables = new URLVariables(); variables.rptName = "report1"; variables.rptFormat = "PDF"; var request:URLRequest = new URLRequest(); request.url = "/buildFile.aspx"; request.method = URLRequestMethod.POST; request.data = variables; navigateToURL(request, "_self"); }
仅供参考,这是当前输出PDF或Excel文件的代码块:
System.Web.HttpContext httpC; httpC = System.Web.HttpContext.Current; httpC.Response.Clear(); httpC.Response.ClearHeaders(); httpC.Response.Expires = 0; switch (ReportFormat) { case "Excel": Response.ContentType = "application/vnd.ms-excel"; break; case "PDF": Response.ContentType = "application/pdf"; ; break; } Response.AddHeader("Content-disposition", "attachment;filename=" + fileName); BinaryWriter binaryWriter = new BinaryWriter(httpC.Response.OutputStream); binaryWriter.Write(result);
Konstantin T.. 6
当用户请求PSD文件时,您的服务器应发送"application/octet-stream"标头.
使用ASP.NET,它可能如下所示:
Response.ClearContent(); Response.ClearHeaders(); // with this header user will be promted to open or download file Response.ContentType = "application/octet-stream"; // with this header, you will suggest to save file with "test.pdf" name Response.AddHeader("Content-Disposition", "attachment; filename=test.pdf"); Response.WriteFile(Server.MapPath("~/test.pdf")); Response.Flush(); Response.Close();
另请参阅此处:使用FileReference类在Flex中下载文件
当用户请求PSD文件时,您的服务器应发送"application/octet-stream"标头.
使用ASP.NET,它可能如下所示:
Response.ClearContent(); Response.ClearHeaders(); // with this header user will be promted to open or download file Response.ContentType = "application/octet-stream"; // with this header, you will suggest to save file with "test.pdf" name Response.AddHeader("Content-Disposition", "attachment; filename=test.pdf"); Response.WriteFile(Server.MapPath("~/test.pdf")); Response.Flush(); Response.Close();
另请参阅此处:使用FileReference类在Flex中下载文件