Skip to content

File uploading is broken due to scoping problem with instanceof #24

Open
@celer

Description

@celer

Hi,

So the function hasFiles in options.js uses 'instanceof' to determine if something is a file, but because of the way instanceof works, outside packages can never actually create a File that will work with instance of.

Imagine a project structure like so:

  • MyProject/
    • upload.js
    • node_modules
      • File/ **
      • ahr2/
        • node_modules/
          • File/ **

** While these are both the same package Javascript sees the objects created from them as having different constructors and therefore instanceof does not work.

The File package in scope of ahr2 is not considered by node to be the same package in scope of upload.js

// This loads the npm File package for my packge
var MyScopedFile = require('File');
...
request.body['file'] = new MyScopedFile('/etc/hosts');

//And inside of ahr2/options.js
if(file instanceof File){ }
//This instanceof will *never* work because node sees MyScopedFile as being different from 
// the same npm package loaded from ahr2/node_modules/File

Our suggested fix is to expose the File object from ahr2, like so:

ahr2.File

And update associated documentation, etc.

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