Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,26 +284,6 @@ Returns the form data as a string. Don't use this if you are sending files or bu

### Integration with other libraries

#### Request

Form submission using [request](https://github.com/request/request):

```javascript
var formData = {
my_field: 'my_value',
my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),
};

request.post({url:'http://service.com/upload', formData: formData}, function (err, httpResponse, body) {
if (err) {
return console.error('upload failed:', err);
}
console.log('Upload successful! Server responded with:', body);
});
```

For more details see [request readme](https://github.com/request/request#multipartform-data-multipart-form-uploads).

#### node-fetch

You can also submit a form using [node-fetch](https://github.com/bitinn/node-fetch):
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
"pkgfiles": "^2.3.2",
"pre-commit": "^1.2.2",
"puppeteer": "^1.20.0",
"request": "~2.87.0",
"rimraf": "^2.7.1",
"semver": "^6.3.1",
"tape": "^5.9.0"
Expand Down
17 changes: 17 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,26 @@ var http = require('http');
var IncomingForm = require('formidable').IncomingForm;
var hasOwn = require('hasown');

var PassThrough = require('stream').PassThrough;

var common = module.exports;

var rootDir = path.join(__dirname, '..');

// Helper to get a remote file as a stream using native http
// Replaces request(url) pattern for testing
// Sets .path property so form-data can extract filename
common.getRemoteStream = function (url) {
var pass = new PassThrough();
// Set path property for filename extraction (mimics request behavior)
pass.path = url;
http.get(url, function (res) {
res.pipe(pass);
}).on('error', function (err) {
pass.destroy(err);
});
return pass;
};
common.dir = {
lib: path.join(rootDir, '/lib'),
fixture: path.join(rootDir, '/test/fixture'),
Expand Down
3 changes: 1 addition & 2 deletions test/integration/test-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var common = require('../common');
var assert = common.assert;
var http = require('http');
var mime = require('mime-types');
var request = require('request');
var fs = require('fs');
var FormData = require(common.dir.lib + '/form_data');
var IncomingForm = require('formidable').IncomingForm;
Expand All @@ -30,7 +29,7 @@ var FIELDS = {
},
remote_file: {
type: mime.lookup(common.dir.fixture + '/unicycle.jpg'),
value: function () { return request(remoteFile); }
value: function () { return common.getRemoteStream(remoteFile); }
}
};
var fieldsPassed = Object.keys(FIELDS).length;
Expand Down
93 changes: 0 additions & 93 deletions test/integration/test-request.js

This file was deleted.

3 changes: 1 addition & 2 deletions test/integration/test-submit-custom-header.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ var common = require('../common');
var assert = common.assert;
var http = require('http');
var mime = require('mime-types');
var request = require('request');
var fs = require('fs');
var FormData = require(common.dir.lib + '/form_data');
var IncomingForm = require('formidable').IncomingForm;
Expand All @@ -29,7 +28,7 @@ var FIELDS = {
},
remote_file: {
type: mime.lookup(common.dir.fixture + '/unicycle.jpg'),
value: function () { return request(remoteFile); }
value: function () { return common.getRemoteStream(remoteFile); }
}
};
var fieldsPassed = Object.keys(FIELDS).length;
Expand Down
3 changes: 1 addition & 2 deletions test/integration/test-submit-custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var common = require('../common');
var assert = common.assert;
var mime = require('mime-types');
var request = require('request');
var fs = require('fs');
var FormData = require(common.dir.lib + '/form_data');

Expand All @@ -27,7 +26,7 @@ var FIELDS = {
},
remote_file: {
type: mime.lookup(common.dir.fixture + '/unicycle.jpg'),
value: function () { return request(remoteFile); }
value: function () { return common.getRemoteStream(remoteFile); }
}
};

Expand Down
3 changes: 1 addition & 2 deletions test/integration/test-submit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
var common = require('../common');
var assert = common.assert;
var mime = require('mime-types');
var request = require('request');
var fs = require('fs');
var FormData = require(common.dir.lib + '/form_data');

Expand All @@ -27,7 +26,7 @@ var FIELDS = {
},
remote_file: {
type: mime.lookup(common.dir.fixture + '/unicycle.jpg'),
value: function () { return request(remoteFile); }
value: function () { return common.getRemoteStream(remoteFile); }
}
};

Expand Down