mholt / PapaParse

Fast and powerful CSV (delimited text) parser that gracefully handles large files and malformed input
http://PapaParse.com
MIT License
12.53k stars 1.15k forks source link

Downloading CSV file with redirect #353

Closed khataev closed 7 years ago

khataev commented 7 years ago

Recently, my csv provider service started to use redirects. This raises error like this (copied from Chrome console):

XMLHttpRequest cannot load http://moex.com/ru/derivatives/open-positions-csv.aspx?d=20161107&t=1. Redirect from 'http://moex.com/ru/derivatives/open-positions-csv.aspx?d=20161107&t=1' to 'http://moex.com/LpSiL/ru/derivatives/open-positions-csv.aspx?d=20161107&t=1' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://micexopen.khataev.com' is therefore not allowed access.

Is it possible to workaround this situation? Here is code snippet of how I invoke PapaParse.

ps: error handler function has several arguments:

error: function(err, file, inputElem, reason)
    {
        // executed if an error occurs while loading the file,
        // or if before callback aborted for some reason
    }

but none of them contain information about redirect url. If it would, I could try to initiate another Papa.parse call.

khataev commented 7 years ago

Seems to me, I've read FAQ not completely - there is note about cross-site requests and that there is no guarantee they will work. So they worked once csv server settings changed ;) So I med up a proxy server with "Access-Control-Allow-Origin" header set to my client server name in order to solve this problem.