Created
August 22, 2023 15:56
-
-
Save VonStruddle/e8bc8f3ebbf230934352cb57d9c4f385 to your computer and use it in GitHub Desktop.
Download file WeWeb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const link = wwLib.getFrontDocument().createElement('a'); | |
const fileName = context.item.data?.['summary']?.['name']; // replace by your file name | |
const apiUrl = context.item.data?.['summary']?.['url']; // replace by your file URL | |
link.href = apiUrl; | |
link.download = fileName; | |
wwLib.getFrontDocument().body.appendChild(link); | |
fetch(apiUrl, { | |
method: 'GET', | |
}) | |
.then(response => { | |
if (response.ok) { | |
return response.blob(); | |
} else { | |
throw new Error('Request failed'); | |
} | |
}) | |
.then(blob => { | |
const blobUrl = URL.createObjectURL(blob); | |
link.href = blobUrl; | |
link.click(); | |
wwLib.getFrontDocument().body.removeChild(link); | |
}) | |
.catch(error => { | |
console.error('Error:', error); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment