Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What content type to force download of text response?

Tags:

I need to stream a file to the Response for saving on the end user's machine. The file is plain text, so what content type can I use to prevent the text being displayed in the browser?

like image 764
ProfK Avatar asked Oct 09 '08 11:10

ProfK


People also ask

What are the content type for streaming?

Podcasts, webcasts, movies, TV shows and music videos are common forms of streaming content.

When to use content-disposition?

In a regular HTTP response, the Content-Disposition response header is a header indicating if the content is expected to be displayed inline in the browser, that is, as a Web page or as part of a Web page, or as an attachment, that is downloaded and saved locally.

How do I download text from a URL?

Click and drag to select the text on the Web page you want to extract and press “Ctrl-C” to copy the text. Open a text editor or document program and press “Ctrl-V” to paste the text from the Web page into the text file or document window. Save the text file or document to your computer.


1 Answers

To be on the safe side and ensure consistent behavior in all browsers, it's usually better to use both:

Content-Type: application/octet-stream Content-Disposition: attachment;filename=\"My Text File.txt\" 
like image 125
Mun Avatar answered Sep 30 '22 06:09

Mun