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

$scope.$on('flow::fileAdded'.. doesn't work #305

Open hank-hong opened 8 years ago

hank-hong commented 8 years ago

The version I used is: angular ~1.2.0 ng-flow ~2

HTML :

<div flow-init="{singleFile:true}" 
        flow-file-added="handlerFileAdded($file, $event, $flow)" >
           <img style="max-height:60px;" flow-img="$flow.files[0]" />
           <span class="btn btn-info" flow-btn flow-attrs="{accept:'image/*'}" >Upload</span>
</div>

JS:

$scope.$on('flow::fileAdded', function (event, flow, file) {
    if(file.size > (1024*1024)){
       log.error('The size of image should be less than 1M');
    }
 });

I want to avoid upload the file whose size is larger than 1M. But the event "on" won't listen to the event "flow::fileAdded", this method won't be triggered. Could someone please help me to resolve it?

Thanks

evilaliv3 commented 8 years ago

@hank-hong: look here for an example of usage in GlobaLeaks: https://github.com/globaleaks/GlobaLeaks/blob/master/client/app/js/controllers/fileupload.js#L4

hank-hong commented 8 years ago

Hello @evilaliv3 Thanks for you response, but the project I created was according to your demo. I also put them in on control, but it also doesn't work in my project. It's weird.

hank-hong commented 8 years ago

By the way, I added and used other method, ex flow-file-success="someHandlerMethod( $file, $message, $flow )" or flow-complete=" ... ", these methods were also not triggered, only flow-file-added works. It's weird!!! Is it possible that flow-init="{singleFile:true}" block them?

pingzh commented 8 years ago

You can take a look at this issue: https://github.com/flowjs/ng-flow/issues/140