Why does this download pdf file code from a non-direct link damage the file?

The code allows download.
But when the file is opened.
The file is damaged.
<%@Language="VBScript"%>
<%Option Explicit%>
 
	<%
	Dim adoStream, stream, fileName, mimeType
	Set adoStream = Server.CreateObject("ADODB.Stream")
 
	fileName = Request.QueryString("file")
	mimeType = Request.QueryString("mime")
 
	adoStream.Open()
	adoStream.Type = adTypeBinary
	'adoStream.LoadFromFile Server.MapPath(fileName)
	adoStream.LoadFromFile Server.MapPath("/s1QZAkAeAKT1chsRu/" & fileName)
	
	
	
	
	If adoStream.Type = adTypeBinary Then
	stream = adoStream.Read()
	Else
	stream = adoStream.ReadText()
	End If
	adoStream.Close()
	Set adoStream = Nothing
 
 
	Response.Buffer = True
	Response.AddHeader "content-disposition", "attachment; filename=" & fileName
	Response.AddHeader "content-length", Len(stream)
 
	Response.ContentType = mimeType
	Response.BinaryWrite stream
	Response.Flush
 
	%>

Open in new window

RepressedRadarAsked:
Who is Participating?
 
R_HarrisonConnect With a Mentor Commented:
Don't ask why, but try adding the below to the very top of your page and see what happens?   If it works you will need to redo your code as this is a special call for PDFs files and will most likely break all other file types - the whole thing gets a bit technical and I can't remember where I read the article that suggested this.
<!--METADATA TYPE="TypeLib" UUID="{414FEE4B-2879-4090-957E-423567FFCFC6}"-->

Open in new window

0
All Courses

From novice to tech pro — start learning today.