Access to PDF Files in the tulip table from custom widget

Hello,
how can I access Files in the tulip table from custom widget ?
In a custom widget, I would like to open PDF stored in tulip table, but when I try, I get an error:
from origin ‘null’ has been blocked by CORS policy

Here is my code to get the content of the PDF stored in the variable “pdf_link”:

async function test() {
let pdf_link = getValue(“pdf_link”);
const response = await fetch(pdf_link);
if (!response.ok) {
throw new Error(
"Erreur lors de la récupération du fichier : " + response.statusText
);
}
const blob = await response.blob();
const file = new File([blob], “document.pdf”, { type: blob.type }); // Simule un fichier
}
test();

Hi @aaries & welcome to the Tulip Community! :tada:

I am wondering a bit more about your use case here - what are you trying to accomplish by opening a PDF from a Tulip Table with a custom widget? I am wondering if there is another way to approach this :slight_smile:

Did you try using the Link-Registration-API?

What is the Link-Registration-API ?

I meant the signURL API.
The Docs and images are stored as a blob and not as a public link. This link will not work from an external source.
You can sign this url and will get one back, that is available for 3 hours or so.

Find the documentation here: Sign cloud storage URLs - Misc.

And in the API unit test here:
Tulip API unit test

The CORS Policy issue could cause from calling it inside the iframe, that is a different origin than the app itself…

1 Like

You can request base64 encoded pdf from tulip table
and display this in custom widget using mozilla pdf lib.

1 Like