Asp classic 要在浏览器中查看的流文件使用哪种内容类型?
我正在尝试使用adodb将文件流式传输到浏览器 用户将获得如下选项:Asp classic 要在浏览器中查看的流文件使用哪种内容类型?,asp-classic,stream,mime-types,content-type,adodb,Asp Classic,Stream,Mime Types,Content Type,Adodb,我正在尝试使用adodb将文件流式传输到浏览器 用户将获得如下选项: 保存文件选项按预期工作 但是openwithfirefox选项给出了gobbledy,并且.htm被附加到文件名的末尾 我推测这与Response.ContentType的设置有关 我试过使用application/pdf,application/octet-stream和application/x-unknown。但是无论我用哪种方法,我总是得到相同的结果 这是怎么回事?我应该使用什么内容类型 用Firefox打开的
保存文件
选项按预期工作
但是openwithfirefox
选项给出了gobbledy,并且.htm被附加到文件名的末尾
我推测这与Response.ContentType
的设置有关
我试过使用application/pdf
,application/octet-stream
和application/x-unknown
。但是无论我用哪种方法,我总是得到相同的结果
这是怎么回事?我应该使用什么内容类型
用Firefox打开的快照
ADODB流代码
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile(fileDirectory & "\" & fileToDownload)
Response.AddHeader "Expires", "0"
Response.AddHeader "Content-Transfer-Encoding", "binary"
Response.AddHeader "Content-Description", "File Transfer"
Response.AddHeader "Content-Disposition", "attachment; filename=" & fileToDownload
Response.AddHeader "Content-Length", objStream.Size
Response.CharSet = "UTF-8"
Response.ContentType = "???" // *** what should I put here? ***
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
除了拥有
Response.ContentType=“application/pdf”
,我还需要拥有Response.AddHeader“Content Type”,“application/pdf”
因此,最终有效的代码是:
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1 'adTypeBinary
objStream.Open
objStream.LoadFromFile(fileDirectory & "\" & fileToDownload)
Response.AddHeader "Expires", "0"
Response.AddHeader "Content-Transfer-Encoding", "binary"
Response.AddHeader "Content-Description", "File Transfer"
Response.AddHeader "Content-Disposition", "attachment; filename=" & fileToDownload
Response.AddHeader "Content-Length", objStream.Size
Response.AddHeader "Content-Type", "application/pdf" '** added this line **
Response.CharSet = "UTF-8"
Response.ContentType = "application/pdf"
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
除了拥有
Response.ContentType=“application/pdf”
,我还需要拥有Response.AddHeader“Content Type”,“application/pdf”
因此,最终有效的代码是:
Dim objStream
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1 'adTypeBinary
objStream.Open
objStream.LoadFromFile(fileDirectory & "\" & fileToDownload)
Response.AddHeader "Expires", "0"
Response.AddHeader "Content-Transfer-Encoding", "binary"
Response.AddHeader "Content-Description", "File Transfer"
Response.AddHeader "Content-Disposition", "attachment; filename=" & fileToDownload
Response.AddHeader "Content-Length", objStream.Size
Response.AddHeader "Content-Type", "application/pdf" '** added this line **
Response.CharSet = "UTF-8"
Response.ContentType = "application/pdf"
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing