function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Suman KuchSuman Kuch 

XMLHttpRequest cannot load https://upload.box.com/api/2.0/files/content. Origin https://idrdev--c.cs41.visual.force.com is not allowed by Access-Control-Allow-Origin

Hi,
I'm developing an upload process from Salesforce to Box to upload files via CORS functionality but I'm failing to make calls to BOX and getting error "XMLHttpRequest cannot load https://upload.box.com/api/2.0/files/content. Origin https://idrdev--c.cs41.visual.force.com is not allowed by Access-Control-Allow-Origin." so could anyone of you please give  me know the solution for this issue?

The Code I'm using to upload files to BOX is..
 
<script type="text/javascript">
    var script= document.createElement('script');
    script.type= 'text/javascript';
    script.src= '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js';
    document.head.appendChild(script);
    function fileUpload(recId) {
        Visualforce.remoting.Manager.invokeAction(
            '{!$RemoteAction.BoxUploadController.createBoxFolder}',
            recId,
            function(result, event){
                if (event.status) {
                    folderID = result.FolderID;
      		        Bearer = result.Bearer;
                    // Get DOM IDs for HTML and Visualforce elements like this
                    var file =document.getElementById('fileinput').files[0];
                    var form = new FormData();
                    var blob = new Blob([file], { type: file.type});
                    form.append('file',file, file.name);
                    form.append('parent_id', folderID);
                    var uploadUrl = 'https://upload.box.com/api/2.0/files/content';
                    var headers = {
                        Authorization: 'Bearer '+Bearer
                    };
                    $.ajax({
                        url: uploadUrl,
                        crossOrigin: true,
                        headers: headers,
                        type: 'POST',
                        processData: false,
                        contentType: true,
                        data: form
                    }).complete(function ( data ) {
                        console.log(data);
                    });
                } else if (event.type === 'exception') {
                    document.getElementById("responseErrors").innerHTML = 
                        event.message + "<br/>\n<pre>" + event.where + "</pre>";
                } else {
                }
            }, 
            {escape: true}
        );
    }
    </script>



Thanks,
Suman K