Skip to content

Instantly share code, notes, and snippets.

@spite
Created April 26, 2014 13:54
Show Gist options
  • Save spite/11320599 to your computer and use it in GitHub Desktop.
Save spite/11320599 to your computer and use it in GitHub Desktop.
function exportZipToSketchfab( zip ) {
setLoadingText( 'Uploading...' );
showLoading( true );
var fd = new FormData();
fd.append('token', settings.sketchfabToken );
fd.append('fileModel', zip );
fd.append('filenameModel', 'model.zip');
function updateProgress( e ) {
if (e.lengthComputable) {
setProgress( e.loaded / e.total );
} else {
setProgress( 0 );
}
}
var result = function () {
var res = JSON.parse(xhr.responseText);
console.log(res);
if (!res.success) {
showMessage( 'Sketchfab upload error: <span class="error">' + res.error + '</span>' );
showLoading( false );
} else {
showMessage( 'Upload success: ID is ' + res.result.id );
showLoading( false );
}
};
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener( 'progress', updateProgress, false);
xhr.addEventListener( 'progress', updateProgress, false);
xhr.addEventListener('load', result, true);
xhr.open('POST', 'https://api.sketchfab.com/v1/models');
xhr.send(fd);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment