Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <form id="the-form" action="" enctype="multipart/form-data" method="POST"> <!--style="display:none"-->
- <input id="myfile" name="modelFile" type="file" class="form-control">
- <input name="token" type="text" ng-model="authorizationUrlToken.value" class="form-control">
- <input name="name" type="text" ng-model="itemToEdit.fields.name.value" class="form-control">
- <input name="description" type="text" value="" class="form-control">
- <input name="tags" type="text" class="form-control">
- <input id="myprivate" name="private" type="checkbox" value="0" class="form-control">
- <input id="mypassword" name="password" type="password" class="form-control">
- <input id="mysubmit" name="Submit" type="submit" value="Submit Upload to SketchFab" class="form-control btn btn-default" tooltip="Upload" title="Upload" />
- </form>
- <script>
- ///////////////////////////////////////////////////////////
- //TEST 3 upload via javascript of sketchfab with SketchfabDataApi
- ////////////////////////////////////////////////////////////
- $scope.UploadModelBySketchfabdataApi = function() {
- var token = $scope.authorizationUrlToken.value;
- var file = jQuery("#myfile")[0].files[0];//.attr("files")[0];
- if (file) {
- var fileName = file.name;
- }
- var fullPathFile = window.location.protocol + "//" + window.location.host;
- fullPathFile = fullPathFile + '/private/' + fileName;
- console.info('START:' + fullPathFile);
- var Swagger = require('swagger-client');
- var fs = require('fs');
- var path = require('path');
- var api = new SketchfabDataApi();
- api.then(function (client) {
- // This is how you authenticate your requests with the "Token" scheme
- client.clientAuthorizations.add("Token",
- new Swagger.ApiKeyAuthorization(
- "Authorization",
- "Token " + token ,
- "header"
- )
- );
- // This is how you upload a file
- client.apis.models.post_v3_models({
- isPublished: 'false',
- modelFile: fs.createReadStream(path.resolve(fullPathFile))
- }).then(function (response) {
- if (response.status === 201) {
- // The model URI is immediately returned, even if processing hasn't finished yet
- console.log('After processing, model will be available at: ' +
- response.headers.location);
- var uid = response.headers.location
- .replace('https://api.sketchfab.com/v3/models/', '');
- // You can poll the processing status to know when the model is ready
- // See how `pollStatus` is implemented below
- pollStatus(client,
- uid,
- function (err, res) {
- console.log(err, res);
- });
- //Redirect to my uri
- window.location.href = window.location.protocol + "//" + window.location.host + "/stealth/#/stealth/models3d/models3d";
- }
- }).catch(function (error) {
- console.error("ERROR ON UPLAOD:" + error);
- });
- }).catch(function (error) {
- console.log("ERROR ON AUTHENTICATION:" + error);
- });
- }
- /**
- * Poll processing status
- * @param {object} client Swagger client
- * @param {string} uid Model uid
- * @param {function} callback will receive (err, result)
- */
- function pollStatus(client, uid, callback) {
- client.apis.models.get_v3_models_uid({
- uid: uid
- }).then(function (response) {
- if (response.obj.status.processing === 'SUCCEEDED') {
- callback(null, response.obj.status);
- } else if (response.obj.status.processing === 'FAILED') {
- callback(response.obj.status.processing, null);
- } else {
- setTimeout(function () {
- console.log(response.obj.status);
- pollStatus(client, uid, callback);
- }, 1000);
- }
- });
- }
- //Funzioni da chima re al submit della form
- //data.onsubmit = function() {
- // //$scope.uploadModel(data);
- // $scope.UploadModelCSharp();
- // return false; // Prevent redirect
- //}
- //jQuery('#the-form').on('submit', uploadModel);
- jQuery('#the-form').submit(function () {
- //TEST 3
- $scope.UploadModelBySketchfabdataApi();
- return false; // Prevent redirect
- });
- </script>
- </html>
Add Comment
Please, Sign In to add comment