asafdav / ng-s3upload

Upload to S3 using AngularJS
MIT License
190 stars 83 forks source link

Dynamic Options #44

Closed sivasiva closed 9 years ago

sivasiva commented 9 years ago

I must be missing something really simple.

Is there a way to specify the bucket or s3-upload-options in the controller instead of in-lining in the template?

For example, is the following setup possible?

myapp.controller('MyCtrl', function ($scope) {

  $scope.s3 = {
    bucket: 'mybucket',
    options: { submitOnChange: false, getOptionsUri: '/api/v1/s3_options', folder: 'some/folder/' }
  }

  $scope.performUpload = false;
}

and the template like so:

<div data-ng-controller='MyCtrl'>
   <div data-s3-upload 
    data-bucket="s3.bucket" 
    data-ng-model="files.first" 
    data-s3-upload-options="s3.options" 
    data-do-upload="performUpload">
  </div>
</div

Thx again, this is a great library to use!

aellerton commented 9 years ago

Yep!

<div ng-controller="mainCtrl">
  <div s3-upload
       bucket="'something'"
       ng-model="product.remote_url"
       s3-upload-options="s3opts"><!-- note! This refers to a var in scope -->
  </div>
</div>

And then in the controller:

app.controller('mainCtrl', function($scope, $log) {
  $scope.product={nothing: "Here yet"};
  $scope.s3opts={getOptionsUri: '/api/policy', folder: 'uploads/', enableValidation: false};
})
asafdav commented 9 years ago

thanks @aellerton