GET Fetch Public File

TMehlhorn
Member

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 Replies 6
dennisedson
Community Manager

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?

Thanks,

Dennis


We are excited to announce that the Community will be launching a weekly newsletter on November 2, 2020!
Sign up today!
TMehlhorn
Member

Essentially this is my javascript code:

const res = await fetch(PUBLIC_FILEPATH);
and then I am processing the res data.
0 Upvotes
tjoyce
Recognized Expert | Platinum Partner

@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
Member

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 Upvotes
tjoyce
Recognized Expert | Platinum Partner

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

TMehlhorn
Member

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

0 Upvotes