Skip to content

Instantly share code, notes, and snippets.

@VonStruddle
Created August 22, 2023 15:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VonStruddle/e8bc8f3ebbf230934352cb57d9c4f385 to your computer and use it in GitHub Desktop.
Save VonStruddle/e8bc8f3ebbf230934352cb57d9c4f385 to your computer and use it in GitHub Desktop.
Download file WeWeb
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