flowjs / ng-flow

Flow.js html5 file upload extension on angular.js framework
http://flowjs.github.io/ng-flow/
MIT License
1.38k stars 303 forks source link

Setting options dynamically #264

Closed dcardosods closed 8 years ago

dcardosods commented 8 years ago

Is there any way other to set options, except .config and flow-init?

In my use case I want to change chunkSize depending on the sum off all files' size added to upload.

Crysalist commented 8 years ago

You can change it by adding the flowInit like this: <div class="col" flow-init flow-name="obj.flow"> Then on your $scope there will be a variable like $scope.obj.flow. Now you can manipulate the options by changing the values in $scope.obj.flow.opts. Eg. $scope.obj.flow.opts.target = "NEWUPLOADPATH"; $scope.obj.flow.upload(); It will now use whatever you set NEWUPLOADPATH to as the path to upload to.

dcardosods commented 8 years ago

I'm already using flow-name and I'm able to change target and other options. But in my use case I need to assign chunkSize when a file is added. I tried doing that on the fileAdded event, but this event is fired after the file is already split in chunks, i.e., inside the bootstrap method, which makes setting scope.obj.flow.opts.chunkSize = newSize irrelevant.

evilaliv3 commented 8 years ago

@dcardosods, have you tried using the initFileFn as documented in https://github.com/flowjs/flow.js/blob/master/README.md ?

Let us know your feedback and eventually load here your working snippet!

dcardosods commented 8 years ago

@evilaliv3 initFileFn was exactly what I needed. Thanks!

PS: It's documented the function expects 2 params, but only a FlowFile is provided to it.