Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('myApp')
- .controller('S3uploadCtrl', function ($scope) {
- console.log(AWS);
- $scope.creds = {
- bucket: 'myBucket',
- accessKey: 'accKey',
- secretKey: 'secKey'
- };
- $scope.upload = function() {
- // Configure The S3 Object
- AWS.config.update({ accessKeyId: $scope.creds.accessKey, secretAccessKey: $scope.creds.secretKey });
- AWS.config.region = 'us-west-2';
- var bucket = new AWS.S3({ params: { Bucket: $scope.creds.bucket } });
- if($scope.file) {
- var params = { Key: $scope.file.name, ContentType: $scope.file.type, Body: $scope.file, ServerSideEncryption: 'AES256' };
- bucket.putObject(params, function(err, data) {
- if(err) {
- // There Was An Error With Your S3 Config
- alert(err.message);
- return false;
- }
- else {
- // Success!
- alert('Upload Done');
- }
- })
- .on('httpUploadProgress',function(progress) {
- // Log Progress Information
- console.log(Math.round(progress.loaded / progress.total * 100) + '% done');
- });
- }
- else {
- // No File Selected
- alert('No File Selected');
- }
- };
- function alert(msg) {
- console.alert(msg);
- }
- });
- "globals": { "AWS" : false }
- "globals": {
- "AWS": false
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement