Skip to content

Commit

Permalink
Update README.md with details about postFile
Browse files Browse the repository at this point in the history
  • Loading branch information
merlinND committed Jul 17, 2014
1 parent 561e56e commit 4bf7c35
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,32 @@ For the sake of clarity, we provide the following two-steps call syntax:
- `getDocumentById(id).getSimilar(cb)` will call `GET /documents/{id}/similar`
- `getDocumentById(id).getRaw(cb)` will call `GET /documents/{id}/raw`
- `getDocumentById(id).postFile(cb)` will call `POST /documents/{id}/file`
- `getDocumentById(id).postFile(config, cb)` will call `POST /documents/{id}/file`
Note that the first function **does not take any callback**. It is simply responsible for building the first part of the request, which is then carried out when calling the sub-function.
A full description of the mapping functions is available in [`api-descriptors.json`](config/json/api-descriptors.json).
### Posting a file associated to a document
The function `getDocumentById(id).postFile(config, cb)` expects a `config` hash containing at least a `file` key from which to obtain the file. It can be a string (path to the file) or a `ReadStream`. It can also contains `contentType` (MIME type) and `filename` keys.
`config` can also be passed as a function. In this case, it is invoked with a callback, which must be called with `(err, config)`.
**Example usage:**
```js
var deliverConfig = function(cb) {
cb({
file: fs.createReadStream('path/to/file.png'),
filename: 'doge.png'
});
};

getDocumentById(id).postFile(deliverConfig, function(err) {
// Handle error if any
});
```
## Utility functions
`anyfetch.js` provides higher level utility functions. They cover classic use-cases that would otherwise require several API calls. When possible, calls are grouped in a single batch call.
Expand Down

0 comments on commit 4bf7c35

Please sign in to comment.