0

I need a way to grab the contents of a CSV file, preferably in just the Angular front-end app, from the network hosting the app. I do believe using the httpClient library will work, but I can't test it until its hosted because any calls from my local host cause a CORS error. I really just need to emulate what the HTML:

<button Type='File" (click)="function($event)"></button>

does. I would like to use FileReader because it seems to work well.

I can also just expose an API with a node server, but if this can work it is preferable so as to not be dependent on another servers status.

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • You could read the csv from the assets folder: https://stackoverflow.com/a/50158243/453959 – spierala Dec 02 '19 at 20:48
  • @spierala unless im mistaken I dont think I can because its not in there and I would need to Read then Write it into the assets folder at runtime for it to be current. Its hard to lay out all the details in a post, but its a corporate system and the csv file i need is being generated by a different tool in someone else's project and being stored in a shared drive on the network. – Cameron Davis Dec 03 '19 at 15:03

1 Answers1

1

The web browser isn't going to be able give you the local file level access that you want for security reasons. Imagine what could happen if scripts could just read from your network whenever they want ;)

Your best option would be to setup a proxy server to handle the requests for you and there you can set the proper CORs policies.

yomateo
  • 2,078
  • 12
  • 17
  • That is what i figured! Thank you for the comment but is there not a way to "copy" the actions taken when using the html file select action? I was hoping there was a way to attach the credentials needed, from the session token or anything. its a bit frustrating that it can be done manually but not automatically. Thanks again for the answer! – Cameron Davis Dec 02 '19 at 21:13