coolaj86/abstract-http-request — Issue #24: File uploading is broken due to scoping problem with instanceof
Author: celer
Created: 2012-03-02 20:37:47+00:00
State: open

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

```javascript
// 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.