Skip to main content
Question

Downloading a File with Javascript

  • May 21, 2025
  • 1 reply
  • 30 views

Forum|alt.badge.img

How can I download a file from the Box API using client-side javascript?  I've tried the following:

var url = 'https://api.box.com/2.0/files/file_id/content';
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.setRequestHeader('Authorization', 'Bearer '+my_token);
xhr.onload = function()
{
	//stuff
}
xhr.onerror = function()
{
        //more stuff
}
xhr.send();

When the request is made, though, the following error is thrown: 

 

XMLHttpRequest cannot load https://api.box.com/2.0/files//content. The request was redirected to 'https://dl.boxcloud.com/d/1/.../download', which is disallowed for cross-origin requests that require preflight.

1 reply

Forum|alt.badge.img

Hi, 

Were you able to fix this issue? I'm also getting the similar issue but with Uploading, please reply if you could fix this?

 

Thanks,

Sumant K