Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I'm trying to use https://github.com/danialfarid/angular-file-upload but apparently I can't access the file

my HTML

 <img 
    src = "{{ userPhotoUrl }}"
    alt = ""
    class = "img-circle img-responsive"
    accept = "image/*"
    data-multiple = "false"
    ng-file-select = "onFileSelect($file)"
>

my Coffescript:

$scope.onFileSelect = ($file) ->
  console.log $file
  $scope.upload = $upload.upload
    url : '/api/upload/photo'
    file : $file
    method : 'POST'
  .progress (e) ->
    console.log 'percent' + parseInt 100.0 * e.loaded / e.total
  .success (data, status, headers, config) ->
    console.log data, status, headers, config

I just get undefined from the console.log($file)

What can be wrong? I tried to put the same logic in

<input type="file" ng-file-select="onFileSelect($file)">

But I get the same result

share|improve this question
    
$files not $file – przno Oct 3 '14 at 14:02
up vote 1 down vote accepted

In HTML change $file to $files

ng-file-select = "onFileSelect($files)"

That's something exposed by the file upload, like similarly you can use $last or $first together with ng-repeat

share|improve this answer
    
Urgh... that's it, thank you! – Francesco Giordano Oct 3 '14 at 15:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.