Friday, 15 April 2011

file upload - node.js gridform + express -


I am trying to stream directly the files in Mongo It seems that the gridform () is a great solution for this is.

I'm already using the express framework and I want to continue to do this by doing this, although examples of gridform use a native HTTP server without express

I've found that express.bodyParser () struggles with the gridform, so instead:

the app. (Express.bodyParser ()); I App Using (express.json ()); App.use (express.urlencoded ());

The part that confuses me, though I now use the gridform within my path, App.post ('/ data / addproperty image', db.addPropertyImage);

export.addPropertyImage = function (req, res) {??? }

Try because I can not get a valid example from var form = gridform (); This claim fails

  export.addPropertyImage = function (req, res) {var mongo = is required ('Mongodb') var prevail = required ('strong'); Var assert = Required ('Thrust'); Var requires DB = ('mongodb'). DB; Var requires server = ('mongodb'). Server; Var Mongo DB = new DB ('test', new server ('localhost', 27017), {w: 1}); MongoDb.open (function (err, db) {var gridform = require ('gridform'); gridform.db = db; gridform.mongo = mongo; var form = gridform (); // returns a custom incoming form. With form); // This return assurance error: incorrect == true}); Res.send ('test'); };   

Edit ...

As stated below, I need to use a specific version of strong qualities = Valid ('GridForm / Node_module / strong ');

This claim now passes, but the form. () Does not seem to trigger anytime. So console.log ('Start Pars'); The bottom line is never hit

  console.log ('start'); Var Mongo = Required ('mongodb') // var farthaidable = requires ('strong'); Var requires strong = ('gridform / node_ module / strong'); Var requires gridfsStream = ('GridForm / Node_Module / Gridfs-Stream'); Console.log (gridfsStream); Var assert = Required ('Thrust'); Var requires DB = ('mongodb'). DB; Var requires server = ('mongodb'). Server; Var Mongo DB = new DB ('test', new server ('localhost', 27017), {w: 1}); Console.log ('Mongo Open'); MongoDb.open (function (err, db) {var gridform = require ('gridform'); gridform.db = db; gridform.mongo = mongo; var form = gridform (); // gives a custom incoming form credible.Iningform ); // This Return Assurance Error: False == True Console.log ('deemed'); // Optionally per-file metadata form .on ('fileBegin', function (name, file) {console log ('mmata'); file.metadata = 'SO meta'}) / / normally as normal Parse. (Reiki, Function (fault, field, files) {console.log ('Start Pars'); // Usage files and fields like today you do var file = files.inpFile1; console.log (file); file.name // File uploaded to file.type // file type [mime] (https://github.com/bentomas/Node-Mime) file.size // file size named "size" for compatibility file ( File length in gridfost). Similar to file.name is included for // compatibility file. Alistered // included for compatibility // file additional gridfi The root file collection used in file.root // is in Mongodiibi ('FS' means the complete collection in Mongo is named 'fs.files') file.id // Object for this file Id}); }); Res.send ('test'); Uses a specific version of    

gridform (1.0.11) When that particular edition is not already installed (the latest 1.0.14 in the NPM repo), this gridform module ( ./ node_modules / Gridform / Node_modules / ).

This means that unless you use that specific module, the claim will fail because forms will be inherited from a different module than you Has been pulled using ('strong') .

To solve this, the version used by gridform is required:

  var is refractory = required ('GridForm' / Node_ module / strong ');    

No comments:

Post a Comment