Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

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

@TonsOfFun

Description

@TonsOfFun

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions