ladjs / superagent

Ajax for Node.js and browsers (JS HTTP client). Maintained for @forwardemail, @ladjs, @spamscanner, @breejs, @cabinjs, and @lassjs.
https://ladjs.github.io/superagent/
MIT License
16.58k stars 1.33k forks source link

Adding an options argument to .field function to enable setting binary option in form-data #1626

Open ywadsk opened 3 years ago

ywadsk commented 3 years ago

In the function (file request-base.js) RequestBase.prototype.field = function (name, value) { ..... this._getFormData().append(name, value); return this; };

Actually Form data class has function to do append(name, value, options), which allow to add binary data, e.g. 'blob'. So if you could change the function to be: RequestBase.prototype.field = function (name, value, options) { // add options argument ..... this._getFormData().append(name, value, options); // simply pass the options to form-data return this; };

Users could add binary data easily. I've tried locally and works fine.