0
我一直在敲打我的頭靠在牆上用這種古怪的行爲在Chrome鉻儲蓄流文件。廣州
我存儲在一個未命名的,無序的狀態在磁盤上的加密文件。當用戶下載文件時,客戶端被重定向到下載處理程序(.ashx),數據被加載到流中,解密併發送到客戶端。
它可以在所有瀏覽器上正常工作,除了chrome文件以.gz文件格式下載並且無法讀取嗎?
我已經剝離出來的流中取出並加密部分的簡潔(記住這工作完全在IE,火狐等)
Private Function StreamFile(ByVal context As System.Web.HttpContext) As Boolean
context.Response.Clear()
context.Response.ClearHeaders()
context.Response.BufferOutput = False
context.Response.ContentType = "application/octet-stream"
context.Response.AddHeader("content-disposition", "attachment;filename=""" & _sFileName & """")
context.Response.AddHeader("content-length", _iSize)
context.Response.Cache.SetNoServerCaching()
context.Response.Cache.SetMaxAge(System.TimeSpan.Zero)
Dim oInputStream As System.IO.Stream = GetStream()
Dim oBufferedStream As New BufferedStream(oFileStream, context.Response.OutputStream)
oBufferedStream.ProcessStreams(True)
context.ApplicationInstance.CompleteRequest()
Return True
End Function
Public Class BufferedStream
Private _oInputStream As Stream
Private _oOutputStream As Stream
Private _bBuffer() As Byte
Public Const DEFAULT_BUFFER_SIZE As Integer = 8192
Public Sub New(ByRef oInputStream As Stream, ByRef oOutputStream As Stream)
_oInputStream = oInputStream
_oOutputStream = oOutputStream
_bBuffer = GetStreamBuffer(ToInteger(_oInputStream.Length))
End Sub
Public Function ProcessStreams(ByVal bCloseStreams As Boolean) As Boolean
Dim iRead As Integer = 0
Dim iStreamLength As Integer = ToInteger(_oInputStream.Length)
Try
iRead = _oInputStream.Read(_bBuffer, 0, _bBuffer.Length)
While iRead > 0
_oOutputStream.Write(_bBuffer, 0, _bBuffer.Length)
iRead = _oInputStream.Read(_bBuffer, 0, _bBuffer.Length)
If iRead < _bBuffer.Length Then System.Array.Resize(_bBuffer, iRead)
End While
If bCloseStreams Then
Close()
End If
Return True
Catch
Return False
End Try
End Function
Public Shared Function GetStreamBuffer(ByVal iStreamSize As Integer) As Byte()
Dim iBufferSize As Integer = iStreamSize - 1
If iBufferSize > DEFAULT_BUFFER_SIZE Then iBufferSize = DEFAULT_BUFFER_SIZE
Dim bBuffer As Byte() = New Byte(iBufferSize) {}
Return bBuffer
End Function
End Class
任何幫助將不勝感激。
這裏是小提琴手的HTTP頭文件時在Chrome下載
HTTP/1.1 200 OK
Date: Fri, 30 Oct 2009 00:01:45 GMT
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
X-AspNet-Version: 2.0.50727
content-disposition: attachment;filename="codeKiwi.txt"
Content-Length: 349
Cache-Control: private, max-age=0
Content-Type: application/octet-stream
注意的是,文件名codekiwi.txt和內容是一些簡單的純文本,該文件被保存爲codekiwi.txt .gz幷包含亂碼。