How would I go about forcing the browser to download media files instead of attempting to stream them? These are static files in my application directory.
A:
You need to modify app.yaml in your project, setting application/octect-stream
as mime_type.
Check this example:
- url: /download
static_dir: static/download
mime_type : application/octect-stream
As correctly stated in comment, it is not a good idea to force a certain mime_type on download.
If your users would prefer to stream your content rather than downloading them, it's their decision and you shouldn't force them to download your files.
You could provide two different links, one with stream and one forcing the save dialog.
systempuntoout
2010-06-19 15:56:48
Faking the mimetype to force download is generally a bad idea.
Nick Johnson
2010-06-19 17:31:06
A:
if you are using java then you can use following code.
//Set content type
resp.setContentType("text/csv" + .getContentType());
//Set header for attachement
resp.setHeader("Content-Disposition","attachment;filename=Myfile.csv");
//Retrieve file from database and convert to byte
resp.getOutputStream().write(b.getFile().getBytes());
//Close stream
resp.getOutputStream().close();
Manjoor
2010-06-21 12:53:09