2

我将如何强制浏览器下载媒体文件而不是尝试流式传输它们?这些是我的应用程序目录中的静态文件。

4

2 回答 2

0

您需要在项目中修改app.yaml,设置application/octect-stream为 mime_type。检查这个例子:

- url: /download
  static_dir: static/download
  mime_type : application/octect-stream

正如评论中正确指出的那样,在下载时强制使用某个 mime_type 不是一个好主意。如果您的用户更愿意流式传输您的内容而不是下载它们,这是他们的决定,您不应强迫他们下载您的文件。
您可以提供两个不同的链接,一个带有流,一个强制保存对话框。

于 2010-06-19T15:56:48.723 回答
0

如果您使用的是 java,那么您可以使用以下代码。

//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();
于 2010-06-21T12:53:09.357 回答