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

Skipper detects incorrect sizes in posted files #3847

Closed
NAlexandrov opened this issue Oct 2, 2016 · 3 comments
Closed

Skipper detects incorrect sizes in posted files #3847

NAlexandrov opened this issue Oct 2, 2016 · 3 comments
Labels

Comments

@NAlexandrov
Copy link

NAlexandrov commented Oct 2, 2016

Sails version: 0.12.6
Node version: 6.7.0
NPM version: 3.10.3
Operating system: macOS 10.12


Why Skipper detects incorrect file size? I created a new Sails app and made next changes:

config/routes.js

'post /upload': 'UploadController.upload',

config/http.js

bodyParser: require('skipper')({
  strict: true,
}),

api/controllers/UploadController.js

var fs = require('fs');

module.exports.upload = function upload(req, res) {
  req.file('files').upload({
    dirname: __dirname,
    maxBytes: 100 * 1024 * 1024,
  }, function (err, files) {
    files.forEach(function (file) {
      // Correct size in stat.size
      var stat = fs.statSync(file.fd);

      // But incorrect size in file.size
      console.log(file.filename, file.size, stat.size);
    });

    res.ok('ok');
  });
};

request.js for post request:

var fs = require('fs');
var request = require('request');

var data = {
    files: [{
        value: fs.createReadStream('message.eml'),
        options: {
            filename: 'message.eml',
            contentType: 'message/rfc822'
        }
    }, {
        value: fs.createReadStream('attachment.gif'),
        options: {
            filename: 'attachment.gif',
            contentType: 'image/gif'
        }
    }, {
        value: fs.createReadStream('updater.js'),
        options: {
            filename: 'updater.js',
            contentType: 'text/javascript'
        }
    }]
};

request.post({
    uri: 'http://localhost:1337/upload',
    rejectUnauthorized: false,
    formData: data
}, function (err, response, body) {
    console.log(err || body);
});

RESULT:

message.eml 152598 88462
attachment.gif 63980 60843
updater.js 2979 2979

ls -la

-rw-r--r--    1 dos   staff  60843 Sep 30 19:59 attachment.gif
-rw-r--r--@   1 dos   staff  88462 Sep 30 19:55 message.eml
-rw-r--r--    1 dos   staff   2979 Sep 13 01:32 updater.js

P.S. All will be ok if I post one file in array. If I post two files:

message.eml 149461 88462
attachment.gif 60843 60843

You can see that skipper detects correct size only in last file.

P.S.S. I tested request.js on Hapi and Express.js+multer. They are detects the correct sizes.

@sailsbot
Copy link

sailsbot commented Oct 2, 2016

Hi @NAlexandrov! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:

  • Provide your Sails version
  • Provide your Node version
  • Provide your NPM version
  • Provide your Operating system

As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!

If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected].

@mikermcneil
Copy link
Member

Hey @NAlexandrov, thanks for the detailed report. @crobinson42 made some progress on this here: https://github.com/balderdashy/skipper/issues/109, so if you'd take a look at his findings and let us know what your results were, that'd be awesome.

@mikermcneil mikermcneil added the bug label Oct 5, 2016
@mikermcneil
Copy link
Member

@NAlexandrov This is now fixed in the latest skipper-disk and skipper-s3 on NPM (cc @sgress454)

@mikermcneil mikermcneil added the waiting to close This label is deprecated. Please don't use it anymore. label Nov 17, 2016
@sailsbot sailsbot removed the waiting to close This label is deprecated. Please don't use it anymore. label Nov 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

3 participants