Is it possible to trigger a document (PDF) download from a link.
As the files are stored in Google storage I’m hoping theres a link parameter which can be applied through a template column.
Additionally, you can make you template in a computed template column with the format you have if you want to set parameters from other columns or related data.
Thanks Maxime,
Yes I’m looking specifically at implementing an open url action which triggers download of a PDF file without the user needing to take any further actions.
I don’t think that this is possible out of the box. But, you might try creating a custom AI Component and asking to trigger an action on load. I am pretty sure that would work!
I attempted to create a prompt that allows the AI component to perform an action on load after a delay of 100 ms. While I couldn’t get it to work with the provided delay value, it still enables us to make the AI execute a custom action upon page load.
Here is the prompt :
1. In the **DATA** section, define only the `Delay` property with a milliseconds value.
2. On component load, automatically retrieve the `Delay` property. If the property is not set, use a default value of 100 milliseconds.
3. Use the retrieved `Delay` property to start a `setTimeout` function.
4. After the specified delay:
a. Dispatch the **Show Notification** action from the **action** section.
5. The **Show Notification** action must be defined in the **action** section.
6. There will be no visual elements, start, or stop button; the action will trigger automatically without any manual intervention.
7. Ensure that all code runs within the component's secure context to avoid violations of Content Security Policy (CSP) and prevent loading external scripts.
If you put the link of the CSV, your browser will trigger the download automatically. I set a gif link, that is why the browser showed it instead of downloading it. Using the CSV should work the way you want. Try it and tell me if it works!
The way files are displayed depends on your browser settings. By default, most browsers open PDFs directly in the browser using a built-in viewer, but this can vary based on your browser’s configuration and any installed extensions that offer alternative viewers. Similarly, XML files may display as plain text in the browser, while Excel files often prompt for download or may open in an external application, depending on the browser’s compatibility settings and any extensions you have.
In my experience, Excel files always download on click, same as Word files. CSVs downloads on Chromium browsers, but not Safari (displayed as text). PDFs never get downloaded.
@Curtis To answer your question I don’t think it is possible with the current configuration of glide. Except if someone find a better answer than me, here are the things that I’ve tried:
I know that in HTML, if you set an url on a <a> tag and add the “download” attribute, it would trigger a download.
Alternatively, you might want to add this script in a JavaScript Column:
// The following code should run as-is; do not add any other code or modifications
// Note: For CORS restrictions, ensure that the server at 'url' allows CORS requests.
const downloadFile = (url, filename = '') => {
if (filename.length === 0) filename = url.split('/').pop();
const req = new XMLHttpRequest();
req.open('GET', url, true);
req.responseType = 'blob';
req.onload = function () {
const blob = new Blob([req.response], { type: 'application/pdf' });
const isIE = false || !!document.documentMode;
if (isIE) {
window.navigator.msSaveBlob(blob, filename);
} else {
const windowUrl = window.URL || window.webkitURL;
const href = windowUrl.createObjectURL(blob);
const a = document.createElement('a');
a.setAttribute('download', filename);
a.setAttribute('href', href);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
};
req.onerror = function() {
console.error("Download failed due to CORS policy.");
};
req.send();
};
downloadFile(p1);