Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not receiving any data on backend (MEAN stack) #196

Closed
Haskabab opened this issue Apr 18, 2014 · 2 comments
Closed

Not receiving any data on backend (MEAN stack) #196

Haskabab opened this issue Apr 18, 2014 · 2 comments

Comments

@Haskabab
Copy link

Hello, I am trying to implement your module but I am encountering a problem; there is no data being sent to my backend. (node.js + express.js)

This is my HTML:

                <div class="form-group">
                    <label for="image">Image:</label>
                    <input type="file" id="uploadedImage" name="uploadedImage" ng-file-select="onFileSelect($files)" >
                </div>

I have the following code in my controller:

$scope.onFileSelect = function($files){
    for( var i = 0; i < $files.length; i++ ){
        var file = $files[i];
        $scope.upload = $upload.upload({
            url: '/api/upload-image/car',
            file: file
        }).progress(function(e){
            console.log('percent: '+parseInt(100.0 * e.loaded / e.total ));
        }).success(function(data, status, headers, config){
            console.log(data);  
        });
    }
};

And on the backend I have this route:

app.post('/api/upload-image/:type', function(req, res){

    console.log(req.files);

});

I have tried both req.files & req.file and both are undefined. So I inspected the whol req object and I could not find ANY data related to the image I have uploaded.

So I'm probably doing something wrong, but I can't seem to figure out what. I saw someone else's issue and they solved it by adding a name&id to the so I tried that without success.

So if you could spot something I am doing wrong or send me in the right direction that would be awesome. I really like your directive and would hate to have to switch to another one.

Thanks in advance,
Nick Verheijen

@danialfarid
Copy link
Owner

Would these help?
#67
#191
#185
#40 (comment)

Monitor the network or put some console log to make sure the file variable is not empty and the file content is being sent over to the server.
If the file is being sent then it would be nodejs express specific question which you could ask on nodejs/express forum or stackoverflow as well. There is not much difference in terms of request content/headers between the post request being sent by plugin and a regular old fashion form submit with input file.

@Haskabab
Copy link
Author

They do indeed! Seems like I forgot to include the bodyparser. Thanks for the quick response. Love the module!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants