

FileSaver.js is the solution to saving files on the client-side, and is perfect for webapps. FileSaver.js implements the saveAs FileSaver interface in browsers that do not natively support it. JavaScript to the rescue! function downloadFile ( file ) : Meow! ` ], 'my-cat.txt' ) // Download it using our function downloadFile (myFile ) Ĭlick on the button below to give it a go. Thanks to FileSaver.js you will be able to save the data of a file in JavaScript as a download in your browser easily. Suppose we’ve generated a file in the browser, how can we serve that file to the user without having to ask the user to click a link. Try it here: cat.jpeg Automating the download We can also supply the name of the file by setting the value of the download attribute, in this example we set it to 'my-cat.jpeg'. The download attribute tells the browser to download a link target when it’s clicked. In this article we’ll learn how to use it and how we can automate its behavior with JavaScript. However, the user can still modify the filename in the save prompt that pops-up. The download attribute can be given a valid filename as its value. For these situations we can use the download attribute. The download attribute is used to inform the browser to download the URL instead of navigating to it hence a prompt shows up, requesting that the user saves the file.

Sometimes we just want to download an image file instead of opening it in the browser.
