gridform icon indicating copy to clipboard operation
gridform copied to clipboard

File id is not available on 'fileBegin', 'end', 'file', or while parsing

Open TonsOfFun opened this issue 11 years ago • 3 comments

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?

TonsOfFun avatar May 25 '14 00:05 TonsOfFun

+1

isarathg avatar May 28 '14 04:05 isarathg

+1

Logic-Seeker avatar May 28 '14 07:05 Logic-Seeker

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!

TonsOfFun avatar May 31 '14 19:05 TonsOfFun