Skip to content

Instantly share code, notes, and snippets.

@vseventer
Created May 27, 2014 16:34
Show Gist options
  • Save vseventer/3835e6cfc5353259afe8 to your computer and use it in GitHub Desktop.
Save vseventer/3835e6cfc5353259afe8 to your computer and use it in GitHub Desktop.
Upload files through a form using Angular with Kinvey.
<doctype html5>
<div class="form-group" ng-controller="UploadCtrl">
<input type="file" class="form-control" ng-file-select="onFileUpload($files)" />
<button class="btn btn-success" ng-click="saveTruck()"> <span class="glyphicon glyphicon-ok"></span>&nbsp;Update Information</button>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.16/angular.min.js"></script>
<script src="angular-file-upload.min.js"></script>
<script src="https://da189i1jfloii.cloudfront.net/js/kinvey-angular-1.1.8.js"></script>
<script>
var App = angular.module('MyApp', [ 'angularFileUpload', 'kinvey' ]);
App.run(function($kinvey) {
KINVEY_DEBUG = true;
var promise = $kinvey.init({
appKey : 'App Key',
appSecret : 'App Secret',
});
});
App.controller('UploadCtrl', ['$scope', '$kinvey', '$upload', function($scope, $kinvey, $upload) {
var files = [ ];
$scope.onFileUpload = function($files) {
files = $files;// Save reference to files for when the submit button is hit.
};
$scope.saveTruck = function() {
for(var i = 0; i < files.length; i += 1) {
$kinvey.File.upload(files[i]).then(function(response) {
console.log('File upload succeeded.', response);
}, function(error) {
console.log('File upload failed.', error);
});
}
};
}]);
angular.bootstrap(document, [ 'MyApp' ]);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment