suprememoocow / fineuploader-express-middleware

Express middleware for fineuploader (aka valums file uploader)
5 stars 2 forks source link

octet-stream not supported #1

Open Shedal opened 11 years ago

Shedal commented 11 years ago

I'm getting this error:

Error: bad content-type header, unknown content-type: application/octet-stream
    at IncomingForm._parseContentType (/Users/shedal/goapp/node_modules/fineuploader-express-middleware/node_modules/formidable/lib/incoming_form.js:238:15)
    at IncomingForm.writeHeaders (/Users/shedal/goapp/node_modules/fineuploader-express-middleware/node_modules/formidable/lib/incoming_form.js:131:8)
    at IncomingForm.parse (/Users/shedal/goapp/node_modules/fineuploader-express-middleware/node_modules/formidable/lib/incoming_form.js:84:8)
    at Object.octetStream [as handle] (/Users/shedal/goapp/node_modules/fineuploader-express-middleware/index.js:93:10)
    at next (/Users/shedal/goapp/node_modules/express/node_modules/connect/lib/proto.js:190:15)
    at store.get.next (/Users/shedal/goapp/node_modules/express/node_modules/connect/lib/middleware/session.js:309:9)
    at /Users/shedal/goapp/node_modules/express/node_modules/connect/lib/middleware/session.js:333:9
    at /Users/shedal/goapp/node_modules/express/node_modules/connect/lib/middleware/session/memory.js:50:9
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)`

I am using the latest versions of all packages, including formidable.

suprememoocow commented 11 years ago

Hi Dimini,

Would you mind sending my the output from an npm ls fineuploader-express-middleware and npm ls formidable?

Many thanks Andrew

Shedal commented 11 years ago

Hi, thanks for quick reply. Here's the output:

$ npm ls fineuploader-express-middleware                                                                                                                                                            
goapp@0.0.1 /var/lib/stickshift/2a92c6b52c0840199612fba80ffa2314/app-root/data/278055                                                                                                                                                
└── fineuploader-express-middleware@0.0.1                                                                                                                                                                                            

$ npm ls formidable                                                                                                                                                                                 
goapp@0.0.1 /var/lib/stickshift/2a92c6b52c0840199612fba80ffa2314/app-root/data/278055                                                                                                                                                
├─┬ connect@2.7.0                                                                                                                                                                                                                    
│ └── formidable@1.0.11                                                                                                                                                                                                              
├─┬ express@3.0.3                                                                                                                                                                                                                    
│ └─┬ connect@2.7.0                                                                                                                                                                                                                  
│   └── formidable@1.0.11                                                                                                                                                                                                            
└─┬ fineuploader-express-middleware@0.0.1                                                                                                                                                                                            
  └── formidable@1.0.11                    

So both packages are of the latest version. The real problem is, formidable hasn't been updated in npm for the past 6 months. Octet stream support for formidable is on GitHub, but not yet in npm. I've no idea why they are not keeping the npm package up-to-date. I guess it worked for you, because you downloaded node-formidable straight from GitHub.

suprememoocow commented 11 years ago

Hi Dmytro,

Indeed, it looks like that is why its working for me: I've got the following in my package.json:

"formidable": "git://github.com/felixge/node-formidable.git",

And since I had installed that first and it's retaining the same version number, it was used instead of downloading the packaged one. As a stop-gap for the moment, you could do the same, but I will try see if I can get some idea of why no releases have been done on node-formidable or possible incorporate the required change into this module until a new release of formidable appears.

Shedal commented 11 years ago

Hi Andrew,

Thanks for the suggestion. Though, I don't like to use unstable (i.e. non-npm) versions, even during development. For now, I've implemented my own simple middleware that does not use node-formidable. It's not full-featured, but it does what I need. In case you're interested:

var fs = require('fs');
var uuid = require('node-uuid');
var path = require('path');

exports = module.exports = function(options) {
  options = options || {};
  var uploadDir = options.uploadDir || '/tmp';

  return function(req, res, next) {
    if(req.xhr && req.header('x-file-name')) {
      //
      // Handle direct async XHR stream data upload.

      var extension = path.extname(req.header('x-file-name'));
      var filename = uuid.v4() + extension;
      var tmpFilePath = path.join(uploadDir, filename);

      var ws = fs.createWriteStream(tmpFilePath);

      ws.on('close', function(err) {
        req.files['fineUpload'] = {
          path: tmpFilePath,
          name: filename,
          type: req.header('x-mime-type')
        };

        next();
      });

      req.pipe(ws);

    } else {
      next();
    }
  };
};
tmartineau commented 11 years ago

Shedal,

That works great! Any chance you will make this a module in NPM?