1

I got an AJAX function that loads a png from a canvas graph element and does (per user choice) open the image in a new browser window or force a download.

While the first works without a problem, I got a problem with adding the file extension to the download. Currently I simply get none, using the following HttpHeaders: image/octet-stream, application/download(force-download, x-download)

Gladly some SO user put a JsFiddle together. 1)

Question: How could I go and append a file extension (.png/.jpeg) to the forced download as seen in the JsFiddle example?

1) Sry, but I don´t know the User name anymore.

4

1 回答 1

1

不幸的是,使用 data uris 是不可能提供文件名的。您可能应该查看 HTML5 BlobBuilder API - http://blogs.msdn.com/b/ie/archive/2012/01/27/creating-files-through-blobbuilder.aspx

即使使用 BlobBuilder,我发现只有 Chrome 承认您提供的文件名,而不是 Firefox。

于 2012-04-26T15:54:54.350 回答