错误下载的PDF文件 - ASP经典 [英] Error in downloaded pdf file - ASP classic

查看:338
本文介绍了错误下载的PDF文件 - ASP经典的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建一个下载管理器,一切似乎工作。但是,我得到下载的文件无法打开。该文件具有正确的名称和.pdf扩展名 - 但我的Mac说,文件无法打开(在服务器作品文件)

 如果的Request.QueryString(downloadFile)<>  然后    strFilePath =使用Server.Mappath(/ _ customerFiles /&放大器;会议(urlMapping中)及/文件/&放大器;的Request.QueryString(downloadFile))    设置objFSO =的Server.CreateObject(Scripting.FileSystemObject的)    如果objFSO.FileExists(strFilePath)然后
        设置OBJFILE = objFSO.GetFile(strFilePath)
        intFileSize = objFile.Size
        设置OBJFILE =什么        strFileName =的Request.QueryString(文件名)
        strFileName =取代(的Request.QueryString(downloadFile),, - )        Response.AddHeader内容处置,附件;文件名=&放大器; strFileName
        Response.ContentType =应用程序/八位字节流
        Response.AddHeader内容长度,intFileSize        设置objStream =的Server.CreateObject(的ADODB.Stream)
        objStream.Open
        objStream.Type = 1'adTypeBinary'
        objStream.LoadFromFile strFilePath        这样做虽然没有objStream.EOS而Response.IsClientConnected
            Response.BinaryWrite objStream.Read(1024)
            Response.Flush()
        循环        objStream.Close
        设置objStream =什么    万一    设置objFSO =没什么万一


解决方案

我知道我迟到了这个问题,但我只是处理类似的东西,并希望分享我的观察,试图把它清除掉。


  1. 我已阅读(抱歉,我没有一个源)的的ADODB.Stream 都必须有。键入调用之前指定。开

  2. 我还设置了流 .Mode 属性为3(意为用于读取打开文件),以prevent文件访问锁定错误,如果多个用户尝试访问该文件在同一时间 - 也必须在调用之前完成<$​​ C $ C>。开

  3. 我曾用不同的 Response.ContentType应用程序/八位字节流,有些问题出现后,我改变了矿响应成功.ContentTypeXXX / XXX。该浏览器将接受它作为一个未知的文件类型,然后提示用户根据注册的程序为文件扩展名打开它。

  4. 开始之前加入响应头,你应该叫 Response.Clear (只是要确保你不发送额外的标记)

  5. 结束后,你的 FileSystemObject的,你应该叫到Response.End (再次,只是要确定)

I'm creating a download manager, and everything seems to work. But the file that I get downloaded can not be opened. The file has the correct name and the extension .pdf - but my Mac says that the file cannot be opened (the file on the server works).

if request.querystring("downloadFile") <> "" then

    strFilePath = Server.MapPath("/_customerFiles/"& session("URLmapping") &"/documents/"& request.querystring("downloadFile"))

    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

    If objFSO.FileExists(strFilePath) Then
        Set objFile = objFSO.GetFile(strFilePath)
        intFileSize = objFile.Size
        Set objFile = Nothing

        strFileName = request.querystring("filename")
        strFileName = replace(request.querystring("downloadFile")," ","-")

        Response.AddHeader "Content-Disposition","attachment; filename=" & strFileName
        Response.ContentType = "application/octet-stream"
        Response.AddHeader "Content-Length", intFileSize

        Set objStream = Server.CreateObject("ADODB.Stream")
        objStream.Open
        objStream.Type = 1 'adTypeBinary '
        objStream.LoadFromFile strFilePath

        Do While Not objStream.EOS And Response.IsClientConnected
            Response.BinaryWrite objStream.Read(1024)
            Response.Flush()
        Loop

        objStream.Close
        Set objStream = Nothing

    End if

    Set objFSO = Nothing

end if

解决方案

I know I'm late getting to this question, but I was just dealing with something similar and wanted share my observations to try to clear it up.

  1. I have read (sorry I dont have a source) that the ADODB.Stream has to have its .Type specified prior to calling .Open
  2. I also set the Stream .Mode property to 3 (meaning "open file for Reading") to prevent file access lock errors if multiple people try to access the file at the same time -- Also must be done before calling .Open
  3. I have had varying success with Response.ContentType "application/octet-stream", and after some problems there, I changed mine to Response.ContentType "xxx/xxx". The browser will accept it as an unknown file type and then prompt the user to open it based on the registered program for that file extension.
  4. Before you start adding Response Headers, you should call Response.Clear (just to be sure you're not sending extra markup)
  5. After closing your FileSystemObject, you should call Response.End (again, just to be sure)

这篇关于错误下载的PDF文件 - ASP经典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆