Chrome not honouring ado.stream filename
The ASP code below grabs the content of a file (thisoutfile - which has a GUID as its file name) and streams it to the browser, providing the suggested filename to save as. This works in all browsers except chrome where the filename offered is the name of the script itself, even when the file name (thisfname) is a single word. If you actually save the file as xls or pdf then it saves it OK.
Any idea why?
Set fs=Server.CreateObject("Scripting.FileSystemObject")
Set f=fs.GetFile(thisoutfile)
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(f.Path)
dataSize = f.size
Response.Buffer = true
Response.CharSet = "UTF-8"
Response.clear
select case ext
case "xls"
response.contentType="application/vnd.ms-excel"
case else
Response.ContentType = "application/x-unknown" ' arbitrary
end select
Response.AddHeader "Content-Length", dataSize
Response.AddHeader "Content-Disposition","attachment;filename=""" & thisfname & ""
Response.flush
do while not adoStream.eos
Response.BinaryWrite adoStream.Read(1024 * 8)
Response.fl开发者_开发技巧ush
loop
Response.End()
adoStream.close
set adoStream=nothing
set f=nothing
set fs=nothing
There is a missing double-quote in the Content-Disposition header and it seems Chrome is not that forgiving. Change that line of code to
Response.AddHeader "Content-Disposition","attachment;filename=""" & thisfname & """"
精彩评论