-
Notifications
You must be signed in to change notification settings - Fork 119
Trying to fix passing formData from form to middleware #31
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
Conversation
….prototype.post method to req.fields object (created new object if undefined). Extend fileInfo with req.fields on 'end' event.
….prototype.post method to req.fields object (created new object if undefined). Extend fileInfo with req.fields on 'end' event.
Has this been added to the master yet? I'm running into the same issue. Thanks. |
Nevermind I just copied your version and it works great. Thanks! |
+1 |
Merged in manually in 0.1.2 and published to npmjs.org. Please let me know if the issue is solved. |
@@ -62,6 +62,7 @@ module.exports = function (options) { | |||
if (!--counter) { | |||
_.each(files, function (fileInfo) { | |||
this.initUrls(fileInfo); | |||
fileInfo = _.extend(fileInfo, self.req.fields); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see this fix in 0.1.4
I've committed the code into 0.1.5 to address your issue. Now, each event handler gets request and response objects in addition to fileInfo. In your case you can use something like: upload.on("end", function (fileInfo, req, res)
{
var filemanager = upload.fileManager({
targetDir: __dirname + "/public/userfiles/" + req.param('user_id'),
targetUrl: "/userfiles/" + req.param('user_id')
});
filemanager.move(fileInfo.name, "", function (err, result)
{
console.dir(result);
})
}); Please let me know if that works for you |
Unless i'm missing something vital, then this isn't working at all. Regardless of what i do, then |
I needed to use 'formData' sent from the client and since the middleware isn't collecting it properly, I tried to make a fix.
This what I did:
Collect formData on 'field' formidable event in UploadHandler.prototype.post method to a req.fields object (created new object if undefined). Extend fileInfo with req.fields on 'end' event. So on upload.on("end", function (fileInfo)), I can have the extra property from formData in fileInfo.
Example use:
In the client:
In the server: