Created
September 9, 2013 15:07
-
-
Save cedricpinson/6496902 to your computer and use it in GitHub Desktop.
This file contains 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
var uploadModel( modelAsBlob, filename ) { | |
var fd = new FormData(); | |
var model = modelAsBlob; | |
fd.append( "fileModel", model, filename ); | |
fd.append( "filenameModel", filename ); | |
// for PRO | |
// fd.append( "private", true); | |
// fd.append( "password", "sdlkgj"); | |
fd.append( "tags", "test upload-js"); | |
fd.append( "description", "This is an example"); | |
fd.append( "title", "Your Title"); | |
fd.append( "token", "TOKEN"); | |
var xhr = new XMLHttpRequest(); | |
xhr.open("POST", 'https://api.sketchfab.com/v1/models'); | |
var result = function(data) { | |
var res = JSON.parse(xhr.responseText); | |
if (res.result !== undefined && | |
res.success === true && | |
res.result.id !== undefined ) | |
console.log("Success"); | |
}; | |
xhr.setRequestHeader('Content-Disposition', filename); | |
xhr.addEventListener("load", result, false); | |
xhr.send(fd); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment