Skip to main content
Question

Uploading Files and Folders to Box

  • May 21, 2025
  • 4 replies
  • 222 views

Forum|alt.badge.img

Hi Folks,

 

I am trying to upload a file using the box API -  https://upload.box.com/api/2.0/files/content, however every time I am receiving the below mentioned error:

 

XMLHttpRequest cannot load https://upload.box.com/api/2.0/files/content. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 400.

 

Could you let me know what I am missing anything or if CORS needs to enabled then what should be the value of CORS as it’s a simple HTML file placed on my desktop.

 

Here is my code:

 

var form = new FormData();

// The content of the file
var fileBody = 'This is a test file';

// JS file-like object
var blob = new Blob([fileBody], { type: 'text/xml' });

// Add the file to the form
form.append('file', blob);
form.append('name', 'testfile');

// Add the destination folder for the upload to the form
form.append('parent_id', '0');

var uploadUrl = 'https://upload.box.com/api/2.0/files/content';

// The Box OAuth 2 Header. Add your access token.
var headers = {
Authorization: 'Bearer mydevToken'
};

$.ajax({
url: uploadUrl,
headers: headers,
type: 'POST',
async: false,
crossDomain: true,
crossOrigin: true,
// This prevents JQuery from trying to append the form as a querystring
processData: false,
contentType: false,
data: form,
success: function (data) {
// Log the JSON response to prove this worked
console.log(data.responseText);
},
error: function (error) {
alert(error);
}
});

 

Thanks in Advance!

4 replies

Forum|alt.badge.img

Hello Sahil,

 

I think that the problem is the fact that, as you said, is a simple HTML on your desktop. So... it is not running on any web server / web application and it does not have a domain that can be used as Origin.

 

Regards,


Forum|alt.badge.img

Hi LoCortes,

 

I tried it by hosting the file on IIS Web Server but still the error is there.


Forum|alt.badge.img

Hello there Sahil,

have you added on the CORS configuration the IP of your server or maybe localhost? probably that is the last step you need to perform the call succesfully.

 

I will try it myself and see if it works.

 

Thank you

 


Forum|alt.badge.img

I am still facing this issue, any answers for this one...