Created
August 4, 2016 17:27
-
-
Save cburnette/6ab2c5a5f681207f207688fd375ca569 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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