1

I am storing some the binary data for some files in a database (yes, I know this can be a bad idea). I am able to get the files out, with the correct content type, since I have stored it. But I'm having trouble getting the file to the client with the right filename. Right now I have the following code in a file called get_file.asp:

sSQL = "SELECT filename, contenttype, binarydata FROM new_attachment WHERE filename = '" & filename & "'"

oRs.Open sSQL, conn, 3, 3

If Not oRs.EOF Then
    Response.ContentType = oRs(1)
    Response.BinaryWrite oRs(2)

End if

This will return files correctly, but with the filename of 'get_file.asp', instead of, say, 'myfile.txt'. The url visited is .../get_file.asp?filename=myfile.txt.

Is there a way I could change the name of the file when the browsers prompts the user to save it somewhere?

1

2 Answers 2

2

You need to send out the correct header:

Response.ContentType = "text/html"
Response.AddHeader "Content-Disposition", "attachment; filename=YOURFILE.TXT"
Sign up to request clarification or add additional context in comments.

Comments

1

You need to add a Content-Disposition header.

The header should look like this:

Content-Disposition: attachment; filename=<name of file>

Side note: The way you are concatenating SQL is open to SQL Injection - you should be using parameters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.