SHARE
TWEET

Untitled

a guest Jun 20th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. angular.module('myApp')
  2. .controller('S3uploadCtrl', function ($scope) {
  3.  
  4.   console.log(AWS);
  5.   $scope.creds = {
  6.     bucket: 'myBucket',
  7.     accessKey: 'accKey',
  8.     secretKey: 'secKey'
  9.   };
  10.  
  11.   $scope.upload = function() {
  12.     // Configure The S3 Object
  13.     AWS.config.update({ accessKeyId: $scope.creds.accessKey, secretAccessKey: $scope.creds.secretKey });
  14.     AWS.config.region = 'us-west-2';
  15.     var bucket = new AWS.S3({ params: { Bucket: $scope.creds.bucket } });
  16.  
  17.     if($scope.file) {
  18.       var params = { Key: $scope.file.name, ContentType: $scope.file.type, Body: $scope.file, ServerSideEncryption: 'AES256' };
  19.  
  20.       bucket.putObject(params, function(err, data) {
  21.         if(err) {
  22.           // There Was An Error With Your S3 Config
  23.           alert(err.message);
  24.           return false;
  25.         }
  26.         else {
  27.           // Success!
  28.           alert('Upload Done');
  29.         }
  30.       })
  31.       .on('httpUploadProgress',function(progress) {
  32.         // Log Progress Information
  33.         console.log(Math.round(progress.loaded / progress.total * 100) + '% done');
  34.       });
  35.     }
  36.     else {
  37.       // No File Selected
  38.       alert('No File Selected');
  39.     }
  40.   };
  41.   function alert(msg) {
  42.     console.alert(msg);
  43.   }
  44. });
  45.      
  46. "globals": { "AWS" : false }
  47.      
  48. "globals": {
  49.     "AWS": false
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top