APIs & Integrations

TMehlhorn
Membre

GET Fetch Public File

There is a reason why I can not use the Fetch API to GET a publicly accessibly file? 

 

I am uploading a CVS data file into the file manger and would like GET and process that data with Vue to render it on the page. Depending on what file type I request sometimes I get a CORS error and sometimes I do not.

Am I missing a setting to allow GET requests to publically accessible files? (the file path directs just fine in the URL bar of a browser)?

6 Réponses
tjoyce
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

GET Fetch Public File

@TMehlhorn - I'm not sure what server you're using to run your Vue code but... are you able to use the server as a proxy and send that to the Vue code?

like, in php I would do 

echo file_get_contents('path_to_csv');

 

essentailly creating my own proxy and then have Vue call the url to my php script instead of the CSV directly

TMehlhorn
Membre

GET Fetch Public File

I am trying to able to do this completely on the front-end.  The end-goal being a self-contained component that can be placed on different servers stacks (On and off hubspot)

0 Votes
tjoyce
Expert reconnu | Partenaire solutions Elite
Expert reconnu | Partenaire solutions Elite

GET Fetch Public File

Unfortunately, CORS is controlled completely by server... so, unless you find an open proxy somehow, you might be out of luck.

TMehlhorn
Membre

GET Fetch Public File

Shouldn't making the file public enable something like this?

0 Votes
dennisedson
Équipe de développement de HubSpot
Équipe de développement de HubSpot

GET Fetch Public File

Hello @TMehlhorn 

Would you mind adding your code block so we can see? 

@jradcliff had a similar question a while back but was a POST rather than a GET.  Unclear if this is related.

@tjoyce , what do  you think?

TMehlhorn
Membre

GET Fetch Public File

Essentially this is my javascript code:

const res = await fetch(PUBLIC_FILEPATH);
and then I am processing the res data.
0 Votes