-
Hi, I want to use the button component to download a file from an API end-point (exposed through PostgREST). The API and functionality works, as long as I have set the http bearer token in the request, which is required. i.e. curl "http://localhost:3001/rpc/document_retrieve?id_p=348822345600733184" \
-H "Authorization: Bearer $TOKEN" \
--output file.png The Here is the SQLPage code, but I am not sure how to set the bearer token to authenticate the request? SELECT 'button' as component;
SELECT
'Download - ' || doc.name as title,
'http://localhost:3001/rpc/document_retrieve?id_p=' || doc.id::text as link,
'download' as icon,
doc.name as download,
'nofollow' as rel
FROM api.documents doc
WHERE
$filename IS NOT NULL AND doc.id = $filename::bigint LIMIT 1; As a result I get this back, which is correct and what I would expect if there is no bearer token: Has anyone any suggestions, or have I missed something and the 'button' component supports this? Thanks in advance for your help. Regards, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
The button component's link parameter creates a client-side link (an Are you connected to the same database from your postgrest server and from sqlpage ? If so, the easiest is probably to create a download page that contains only a download button which contains the entire file as a data url: SELECT 'button' as component;
SELECT
'Download - ' || doc.name as title,
'data:' || doc.mime_type || ';base64,' || encode(doc.data::bytea, 'base64') as link,
'download' as icon,
doc.name as download,
'nofollow' as rel
FROM api.documents doc
WHERE
$filename IS NOT NULL AND doc.id = $filename::bigint LIMIT 1; |
Beta Was this translation helpful? Give feedback.
-
Thank-you @lovasoa , Thanks for the guidance, you suggestion worked and the Now I can download and display the content in the page now; works brilliantly.
Kind Regards, |
Beta Was this translation helpful? Give feedback.
-
To anyone stumbling upon this discussion: SQLPage v0.37 adds a new download component that helps in this exact case. It's not yet released, but already testable on docker |
Beta Was this translation helpful? Give feedback.
Thank-you @lovasoa ,
Thanks for the guidance, you suggestion worked and the
'data:' ...
additions were what I needed to get it all working! (as I had previously tried this approach before exploring the url for the link approach).Now I can download and display the content in the page now; works brilliantly.