Skip to content

Commit

Permalink
add metadata for form-data file field
Browse files Browse the repository at this point in the history
  • Loading branch information
dotcypress committed Oct 15, 2014
1 parent bdb7bc1 commit 669200a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ Here's some examples of valid `no_proxy` values:
* `google.com:443, yahoo.com:80` - don't proxy HTTPS requests to Google, and don't proxy HTTP requests to Yahoo!
* `*` - ignore `https_proxy`/`http_proxy` environment variables altogether.

## UNIX Socket
## UNIX Socket

`request` supports the `unix://` protocol for all requests. The path is assumed to be absolute to the root of the host file system.
`request` supports the `unix://` protocol for all requests. The path is assumed to be absolute to the root of the host file system.

HTTP paths are extracted from the supplied URL by testing each level of the full URL against net.connect for a socket response.

Expand Down Expand Up @@ -231,7 +231,14 @@ var formData = {
my_field: 'my_value',
my_buffer: new Buffer([1, 2, 3]),
my_file: fs.createReadStream(__dirname + '/unicycle.jpg'),
remote_file: request(remoteFile)
remote_file: request(remoteFile),
custom_file: {
value: fs.createReadStream('/dev/urandom'),
options: {
filename: 'topsecret.jpg',
contentType: 'image/jpg'
}
}
};
request.post({url:'http://service.com/upload', formData: formData}, function optionalCallback(err, httpResponse, body) {
if (err) {
Expand Down Expand Up @@ -311,7 +318,7 @@ If passed as an option, `auth` should be a hash containing values `user` || `use

`sendImmediately` defaults to `true`, which causes a basic authentication header to be sent. If `sendImmediately` is `false`, then `request` will retry with a proper authentication header after receiving a `401` response from the server (which must contain a `WWW-Authenticate` header indicating the required authentication method).

Note that you can also use for basic authentication a trick using the URL itself, as specified in [RFC 1738](http://www.ietf.org/rfc/rfc1738.txt).
Note that you can also use for basic authentication a trick using the URL itself, as specified in [RFC 1738](http://www.ietf.org/rfc/rfc1738.txt).
Simply pass the `user:password` before the host with an `@` sign.

```javascript
Expand Down Expand Up @@ -447,7 +454,7 @@ The first argument can be either a `url` or an `options` object. The only requir
tunneling proxy.


The callback argument gets 3 arguments:
The callback argument gets 3 arguments:

1. An `error` when applicable (usually from [`http.ClientRequest`](http://nodejs.org/api/http.html#http_class_http_clientrequest) object)
2. An [`http.IncomingMessage`](http://nodejs.org/api/http.html#http_http_incomingmessage) object
Expand All @@ -461,7 +468,7 @@ There are also shorthand methods for different HTTP METHODs and some other conve

This method returns a wrapper around the normal request API that defaults to whatever options you pass in to it.

**Note:** You can call `.defaults()` on the wrapper that is returned from `request.defaults` to add/override defaults that were previously defaulted.
**Note:** You can call `.defaults()` on the wrapper that is returned from `request.defaults` to add/override defaults that were previously defaulted.

For example:
```javascript
Expand Down Expand Up @@ -633,10 +640,10 @@ request({url: url, jar: j}, function () {
To inspect your cookie jar after a request

```javascript
var j = request.jar()
var j = request.jar()
request({url: 'http://www.google.com', jar: j}, function () {
var cookie_string = j.getCookieString(uri); // "key1=value1; key2=value2; ..."
var cookies = j.getCookies(uri);
var cookies = j.getCookies(uri);
// [{key: 'key1', value: 'value1', domain: "www.google.com", ...}, ...]
})
```
Expand Down
7 changes: 6 additions & 1 deletion request.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,12 @@ Request.prototype.init = function (options) {
var requestForm = self.form()
for (var formKey in formData) {
if (formData.hasOwnProperty(formKey)) {
requestForm.append(formKey, formData[formKey])
var formValue = formData[formKey]
if (formValue.hasOwnProperty('value') && formValue.hasOwnProperty('options')) {
requestForm.append(formKey, formValue.value, formValue.options)
} else {
requestForm.append(formKey, formValue)
}
}
}
}
Expand Down

0 comments on commit 669200a

Please sign in to comment.