'How to download in-memory file object in Javascript?
I have an in-memory file object like this in Javascript:
{
name: "1_mRf78VMrVHjBMQpz6PYmiw.jpeg",
lastModified: 1549023843303,
lastModifiedDate: Fri Feb 01 2019 17:54:03 GMT+0530 (India Standard Time),
webkitRelativePath: "",
size: 265437,
}
How can I download it?
var link = document.createElement("a");
document.body.appendChild(link);
link.download =element.artifactName;//file name
link.href = element.artifact;//file object
link.click();
It is downloading corrupted file instead of original file.
Solution 1:[1]
Sorry, I had difficulty following your solution. I was able to come up with this:
var a = document.createElement('a');
a.href = window.URL.createObjectURL(file);
a.download = 'right.png';
a.click();
Where the file on line 2 is a reference to the file object.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nate |
