Skip to content

Instantly share code, notes, and snippets.

@ry8806
Last active November 13, 2019 04:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ry8806/e142390211ddc5199ce9 to your computer and use it in GitHub Desktop.
Save ry8806/e142390211ddc5199ce9 to your computer and use it in GitHub Desktop.
Amazon S3 Upload to Bucket angularJS app and controller
// JavaScript source code
var uploaderApp = angular.module('uploaderApp', ['ngFileUpload']);
uploaderApp.run();
uploaderApp.controller('UploadController', ['$scope', 'Upload', 'S3UploadService', function ($scope, Upload, S3UploadService) {
$scope.uploadFiles = function (files) {
$scope.Files = files;
if (files && files.length > 0) {
angular.forEach($scope.Files, function (file, key) {
S3UploadService.Upload(file).then(function (result) {
// Mark as success
file.Success = true;
}, function (error) {
// Mark the error
$scope.Error = error;
}, function (progress) {
// Write the progress as a percentage
file.Progress = (progress.loaded / progress.total) * 100
});
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment