尝试将PDF文件从server1流式传输到server2获取文件是“损坏的文件”

时间:2011-11-09 13:38:21

标签: asp.net file-io pdf-generation

我在server1文件夹路径中有pdf和doc文件(d:\ files \ a.pdf)现在我想读取位于server1中的文件 server2并在弹出窗口中显示选项save and open。

下面的代码我写在server1:

如果是File.Exists(d:\ files \ a.pdf)那么             Dim fs As New FileStream(isFullFilePath& filename,FileMode.Open,FileAccess.Read,FileShare.Read)             '尝试             尝试

            fs = New FileStream(isFullFilePath & filename, FileMode.Open, FileAccess.Read, FileShare.Read)
            '        Catch ex As FileNotFoundException
            'UploadDoc.PostedFile.SaveAs(UploadDoc.PostedFile.FileName)
            '    fs = New FileStream(UploadDoc.PostedFile.FileName, FileMode.Open, FileAccess.Read, FileShare.Read)
            'End Try

            Dim byteArray(fs.Length) As Byte
            fs.Read(byteArray, 0, fs.Length)

            Response.ContentType = "application/pdf"
            Response.BinaryWrite(byteArray)

        Catch ex As Exception
        Finally
            fs.Close()

        End Try

并在server2中:

            Dim objHttpWebRequest As HttpWebRequest
            Dim objHttpWebResponse As HttpWebResponse
            objHttpWebRequest = HttpWebRequest.Create(DownloadURL)
            objHttpWebRequest.Method = WebRequestMethods.Http.Post

            objHttpWebRequest.Timeout = 600000
            objHttpWebRequest.MaximumResponseHeadersLength = 80000000
            objHttpWebResponse = objHttpWebRequest.GetResponse()

            If objHttpWebResponse.StatusCode = HttpStatusCode.OK Then

                'Dim dataStream As Stream = objHttpWebResponse.GetResponseStream

                Dim BArr(objHttpWebResponse.ContentLength - 1) As Byte
                'Dim fs As StreamWriter

                'Request.InputStream.Read(BArr, 0, objHttpWebResponse.ContentLength)
                objHttpWebResponse.GetResponseStream.Read(BArr, 0, objHttpWebResponse.GetResponseStream.ReadByte)

                Response.ContentType = "application/pdf"
                Response.Charset = "UTF-8"
                Response.AddHeader("Content-Disposition", "attachment;filename=" & strFileNameID(0))
                Response.AddHeader("Content-Length", objHttpWebResponse.ContentLength)
                Response.BinaryWrite(BArr)

但是在花费8小时后获得错误PDF是损坏.....

请帮帮我

提前致谢 Raghvendra

1 个答案:

答案 0 :(得分:0)

您的网站是否已启用压缩功能?我不知道服务的服务,但我知道压缩可以打破浏览器的pdf - 你可能会遇到同样的问题。

这是与遭受压缩问题的人的链接:

http://www.griffincaprio.com/blog/2006/11/iis-http-compression-and-streaming-pdfs-dont-do-it.html