Reputation: 110
I have file object
var File = new File(["aa"], "dek_iv");
can I download this one using JavaScript or jQuery
Upvotes: 2
Views: 15091
Reputation: 1
function downloadFile() {
var file = new File(["aa"], "dek_iv.txt");
var link = document.createElement("a");
link.download =file.name;
link.href = file;
link.click();
}
<button onclick="downloadFile()">Download File</button>
Upvotes: 0
Reputation: 1896
Here is an Example how you can download your file Object.
But this will return nothing since the file size is too small for the system to read.
function downloadFile() {
var file = new File(["aa"], "dek_iv.txt");
var link = document.createElement("a");
link.download =file.name;
link.href = file;
link.click();
}
<button onclick="downloadFile()">Download File</button>
Upvotes: 6