Join the Stack Overflow Community
Stack Overflow is a community of 6.4 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am uploading image my code working fine when I use below HTML

<html>
<head></head>
<body>
 <form action="http://www.example.com/customers/5832e319f1f1e5cc296e8802" method="post" enctype="multipart/form-data">
  Upload: <input type="file" name="upload_image"><br/>
  <input type="submit" value="submit">
 </form>
<body>
</html>

But when I use below code its not working. I want run my code using AngularJS

HTML:

<input type="file" name="file" id="file" 
onchange="angular.element(this).scope().uploadFile(this.files)"/>

JavaScript:

 $scope.uploadFile = function (files) {
    var fd = new FormData();

    fd.append("file", files[0]);

    $http.post(properties.customerUploadImage_path + "/" + checkprofile, fd,                    {
        withCredentials: true,
        headers: {
            enctype: 'multipart/form-data',
        }
    }).success(function (response) {
        console.log(response);
    }).error(function (err) {
        console.log('sss');
    });
};
share|improve this question

put on hold as off-topic by Daniel A. White, TZHX, Andrew Li, Jan Dvorak, Machavity 14 hours ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – Daniel A. White, TZHX, Andrew Li, Jan Dvorak, Machavity
If this question can be reworded to fit the rules in the help center, please edit the question.

    
define not working. – Daniel A. White yesterday
    
angularjs code not upload my data – Addi Khan yesterday
4  
Is it even hitting the angular code? That's a really weird way to call a scope funtion – George yesterday
    
i test above code html its working fine, when i using second angularjs code for my project its not working – Addi Khan yesterday
    
Try changing your html attribute like this onchange="$scope.uploadFile(this.files)" – George yesterday

I have made some corrections in your above code. Hope it helps you.

html

<input type="file" name="file" id="file" onChange="angular.element(this).scope().uploadFile(this)"/>

Js file

$scope.uploadFile = function(file) {
    var file = file.files[0];
    var fd = new FormData();
    fd.append('file', file);

    $http.post(properties.customerUploadImage_path + "/"+checkprofile, fd, {
        withCredentials: true,
        transformRequest: angular.identity,
        headers: {
          'Content-Type': 'multipart/form-data'
        } 
    }).success( function (response) { 
          console.log(response);
       }).error(function (err) { 
          console.log('sss');
       });


}; 
share|improve this answer

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