14

I am trying to use saveAs interface as explained here

For the moment, I only worry about Google Chrome, and I uses latest Canary (Version 27.0.1429.0 canary)

Qn1: the article says.

The W3C File API includes a FileSaver interface, which makes saving generated data as easy as saveAs(data, filename), though unfortunately it will eventually be removed from the spec.

Why it would be removed?

Qn2: Below code.

if (window.saveAs) {
    window.saveAs(blob, name);
}else{
    console.log("saveAs not supported")
}

prints

saveAs not supported 

So chrome doesn't support saveAs. That is not the impression I have reading many article online.

bsr
  • 57,282
  • 86
  • 216
  • 316
  • I would immediately assume because it would allow an attacker to save a malicious file on the user's computer. – Daedalus Mar 04 '13 at 21:49
  • 8
    @Daedalus: well its still not entirely impossible without the `saveAs()` function, just create a small fiddle for it http://jsfiddle.net/shivasaxena/qnYk4/3/ – Shiva Jul 18 '14 at 09:34
  • 1
    @Shiva - perfect, works great - you should post this as an alternative to a function that is going away. – Robb Sadler Nov 06 '15 at 23:18
  • 1
    @Shiva great solution but maybe not set it up to instantly download when you click on your link. – perry Jan 31 '17 at 00:24

1 Answers1

9

this is a polyfill, as explained in the article. You have to load the javascript file listed in the article, save it in your resources and link to it in your code: The repository is there: https://github.com/eligrey/FileSaver.js

There are limitations in Chrome, though. If file already saved, the new saving name is incremented : myFile(1), then myFile(2), etc.

I have now a bug on Chrome, which tells can it cannot OPEN the file, but it is just a false warning, as the file is well SAVED, which is the point.

Kara
  • 6,115
  • 16
  • 50
  • 57
Pierre
  • 91
  • 1
  • 2