1

I use https://github.com/nervgh/angular-file-upload/ and I need to send file size to my backend server.

I don't find any solution, this is header that I receive:

{
  filename:'new02.png',
  headers:{
    'content-disposition':'form-data; name="files"; filename="new02.png"',
    'content-type':'image/png'
  }
}
3
  • On the demo page, i look the Json return by code, there's a length. function onAfterAddingFile return an object with a _file and a length Commented Apr 28, 2016 at 8:01
  • It not pass header like Content-Length... Commented Apr 28, 2016 at 8:03
  • You just have to send your size length with the right property... You can send what you want at your backend server, you've a length so send it Commented Apr 28, 2016 at 8:05

2 Answers 2

1
$scope.uploadFile = function(files) {
files[0].type; //MIME type
files[0].size; //File size in bytes
}; 
Sign up to request clarification or add additional context in comments.

1 Comment

I also use the same logic
0

I'm using angular-file-upload too and a node.js server.

This is how I upload my file in my angular controller:

$scope.uploadInternationalFile = function(file) {
    if (file && file.length) {
        file.upload = Upload.upload({
            url: '/api/upload',
            method: 'POST',
            file: file
        });
        file.upload.then(function(response) {
            // file Sent
        });
    }
};

And I receive my file on my server like this with npm 'multer' package:

module.js

var privateStorage = multer.diskStorage({
    destination: function(req, file, callback) {
            callback(null, './files/');
        },
        filename: function(req, file, callback) {
            callback(null, file.originalname);
        }
    });

    var limits = {
        fieldNameSize: 100,
        fileSize:20000000,
        files: 1,
        fields: 5
    };

    var self = module.exports = {
        uploadPrivate: multer({
            storage:privateStorage,
            limits:limits
        }).single('file')
    };

And this is my API:

var fileUpload = require('module.js');
    app.post('/api/upload', function(req, res) {
        fileUpload.uploadPrivate(req, res, function(err) {
            if (err) {
                // There is an upload error
            }
            else {
                // Your file has been sent
            }
        }
    });

Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.