Ask the user to download a file

This commit is contained in:
Mylloon 2022-10-28 19:29:11 +02:00
parent 84b2047008
commit 9d49a5f581
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -30,10 +30,30 @@ const main = () => {
pub_key
);
console.log(decrypted_file);
// Send the file to the user
const blob = new Blob([decrypted_file], {
type: "application/json",
});
const url = URL.createObjectURL(blob);
download(url, "text.txt"); // Retrieve the original filename
} else {
console.error("Download failed.");
}
};
});
};
/**
* Ask the user to download a file
* @param path URL
* @param filename filename
*/
const download = (path, filename) => {
const anchor = document.createElement("A");
anchor.href = path;
anchor.download = filename;
document.body.appendChild(anchor);
anchor.click();
document.body.removeChild(anchor);
};