Retrieve CSV content using AXIOS GET and VUE JS - returns time out error

Viewed 151

I have a CSV file from an external host.

I'd like to retrieve the content of the CSV file and read it in my VUE JS component.

For example, CSV location: https://my-host.com/file-name.csv

let host = 'https://host-name.com/';
let filePath = 'file-name.csv';
try {
  let response = await axios.get(`${host}${filePath}`, {}, {});
  this.csv = response.data;
} catch (err) {
  console.log(err);
}

I get the following error: net::ERR_CONNECTION_TIMED_OUT:

Error: Network Error
    at createError (createError.js:16)
    at XMLHttpRequest.handleError (xhr.js:69)

I've tried to configure axios with:

axios.defaults.timeout = 500000;

Any other suggestions?

Thanks.

1 Answers

I managed to solve the problem. Can't access external URL from the front-end due to cors policy.

Open a server endpoint that deals with external file access. The front-end reaches the new endpoint which returns the file's content.

Related