I am trying to process onedrive files in client javascript, but first I need to use XMLHttpRequest to load the file. Onedrive supports cors for a large number of operations, but the following problem occurs for loading a file in javascript:
As mentioned here: onedrive rest api manual
I can send a request:
GET https://apis.live.net/v5.0/FILE_ID/content?access_token=ACCESS_TOKEN
and it will respond with a location header redirecting the browser to the file. The problem is that when I send these requests via XHR, the browser always sends the Origin header with the request. For the first request described above, onedrive also responds with the Access-Control-Allow-Origin: * header, so the request is allowed in the browser. However, when the browser is redirected to the actual file location, this resource does not have an Access-Control-Allow-Origin header, so the browser rejects the XHR request (chrome sends the Origin header set to null for the redirect request).
I also tried to get the location, but not redirecting automatically, and then sending another XHR request, this will set the source header to the domain of my site, but the result will be the same.
As I mentioned at the beginning, I need to process the data in javascript, so I am not asking about how to download onedrive files to the hard drive. I need javascript data to be available on a webpage.
I know that I can use server-side programming to get the file data for me and then send it to the client, but for my application this is not an option (at least this is not what I am asking for at the moment).
If there is no way to do this, does anyone have an idea why they will implement their api in this way? To allow javascript to get the location through cors and redirect, but not include the cors header for the redirected resource. Why not just deny cors in the first place? This is mistake?