mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2024-12-25 05:43:46 +01:00
Use the FileSaver library to download
This commit is contained in:
parent
27df5105e6
commit
16b07ae25c
@ -5,7 +5,7 @@ draft: false
|
||||
---
|
||||
<script src="/js/getFullDataPath.js" type="text/javascript"></script>
|
||||
<script src="/js/getTextFromFile.js" type="text/javascript"></script>
|
||||
<script src="/js/downloadData.js" type="text/javascript"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/file-saver@2.0.2/dist/FileSaver.min.js"></script>
|
||||
<script src="/js/Base64ToBlob.js" type="text/javascript"></script>
|
||||
<script>
|
||||
|
||||
@ -28,12 +28,13 @@ draft: false
|
||||
var key = ["file", "fileBase64"]
|
||||
if (params.has(key[0])) {
|
||||
var filename = params.get(key[0]);
|
||||
var textPromise = getTextFromFileUrlAsync(filename)
|
||||
var text = await getTextFromFileUrlAsync(filename)
|
||||
$("#btn_download").click(function () {
|
||||
window.open(filename, "_self");
|
||||
var b = new Blob([text],{type:"text/plain;charset=utf-8"});
|
||||
saveAs(b, filename.substring(filename.lastIndexOf('/')+1))
|
||||
})
|
||||
$('#fileTitle').text(filename);
|
||||
$('#fileContent').text(await textPromise)
|
||||
$('#fileContent').text(text)
|
||||
$('#file').show();
|
||||
$("#div_btn").show();
|
||||
|
||||
@ -41,7 +42,7 @@ draft: false
|
||||
var base64 = params.get(key[1]);
|
||||
$("#btn_download").click(function () {
|
||||
const blob = base64ToBlob(base64, "text/plain")
|
||||
downloadData(blob, "file.dat")
|
||||
saveAs(b, "file.dat")
|
||||
})
|
||||
$('#fileTitle').hide()
|
||||
$('#fileContent').text(atob(base64))
|
||||
|
@ -1,11 +0,0 @@
|
||||
function downloadData(data,fileName) {
|
||||
const url=window.URL.createObjectURL(data)
|
||||
const a = document.createElement('a');
|
||||
a.style.display = 'none';
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
document.body.removeChild(a)
|
||||
}
|
Loading…
Reference in New Issue
Block a user