File id is not available on 'fileBegin', 'end', 'file', or while parsing
I have successfully setup a simple express app utilizing gridform for file uploads to GridFS. The problem I have is I would like to use the file object id for logging/enqueueing.
router.post('/files', function(req, res) {
// Assume you have gridform setup
var form = gridform();
form.on('fileBegin', function (name, file) {
console.log('on fileBegin\n');
console.log(file);
console.log('\n');
});
form.parse(req, function (err, fields, files) {
console.log('while parsing\n');
console.log(files.file);
console.log('\n');
});
form.on('file', function (name, file) {
console.log('on file\n');
console.log(file);
console.log('\n');
});
form.on('end', function (name, file) {
console.log('on end:\n');
console.log(file);
console.log('\n');
});
});
Gives me this
on fileBegin:
{ domain: null,
_events: {},
_maxListeners: 10,
name: 'IMG_4073.jpg',
path: 'IMG_4073.jpg',
type: 'image/jpeg',
size: 0,
root: null,
id: null,
lastModified: Sat May 24 2014 16:28:33 GMT-0700 (PDT) }
on file:
{ domain: null,
_events: {},
_maxListeners: 10,
name: 'IMG_4073.jpg',
path: 'IMG_4073.jpg',
type: 'image/jpeg',
size: undefined,
root: undefined,
id: undefined,
lastModified: Sat May 24 2014 16:28:33 GMT-0700 (PDT) }
while parsing:
{ domain: null,
_events: {},
_maxListeners: 10,
name: 'IMG_4073.jpg',
path: 'IMG_4073.jpg',
type: 'image/jpeg',
size: undefined,
root: undefined,
id: undefined,
lastModified: Sat May 24 2014 16:28:33 GMT-0700 (PDT) }
on end:
undefined
I realize on end doesn't return the file, but I was desperate. Is there something I am missing?
+1
+1
This seems to do the trick of getting me the id when I want it, though it feels like an unnecessary hack. Furthermore I did notice while playing with gridform's tests I can access the id inside the parse block. This indicates to me there is something wrong with the copy I am using in my application or with my application's implementation or configuration. Any advise would be greatly appreciated.
:beers: Cheers!