Skip to content

Instantly share code, notes, and snippets.

@cburnette
Created August 4, 2016 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cburnette/6ab2c5a5f681207f207688fd375ca569 to your computer and use it in GitHub Desktop.
Save cburnette/6ab2c5a5f681207f207688fd375ca569 to your computer and use it in GitHub Desktop.
// The Box Auth Header. Add your access token.
var headers = { Authorization: 'Bearer @ViewBag.AccessToken'};
var uploadUrl = 'https://upload.box.com/api/2.0/files/content';
var files = fileSelect.files;
var formData = new FormData();
formData.append('files', files[0], files[0].name);
// Add the destination folder for the upload to the form
formData.append('parent_id', '0');
$.ajax({
url: uploadUrl,
headers: headers,
type: 'POST',
// This prevents JQuery from trying to append the form as a querystring
processData: false,
contentType: false,
data: formData
}).complete(function ( data ) {
uploadButton.innerHTML = 'Upload';
// Log the JSON response to prove this worked
console.log(data.responseText);
location.reload(true);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment