Permalink
Browse files

readme

  • Loading branch information...
0 parents commit 9806aea9cffc72ce261c46288fd3c302d703622f Ryan French committed Mar 28, 2012
Showing with 104 additions and 0 deletions.
  1. +104 −0 README.md
104 README.md
@@ -0,0 +1,104 @@
+# poster
+Async node module for uploading local/remote files over multipart.
+
+## Install
+<pre>
+ npm install poster
+</pre>
+
+Or from source:
+
+<pre>
+ git clone git://github.com/rfrench/poster.git
+ cd poster
+ npm link
+</pre>
+
+## post(url, options, callback[err, data])
+
+ - `uploadUrl`: Whether to follow redirects or not. Can be a number (of max redirects), `true` (which translates to 20) or `false` (default).
+ - `method`: HTTP method type. Defaults to `POST`.
+ - `fileId`: File ID parameter name of the file. Defaults to `Filedata`.
+ - `fields`: Optional form parameters.
+ - `maxFileSize`: Maximum file size allowed to be uploaded in bytes. Disabled by default.
+ - `maxRedirects`: Total # of redirects allowed before giving up downloading the file. Defaults to `5`.
+ - `downloadAgent`: Use your own http.Agent for downloading files. Defaults to the global agent.
+ - `uploadAgent`: Use your own http.Agent for uploading files. Defaults to the global agent.
+ - `agent`: If supplied, this value will use the same agent for both the downloadAgent and uploadAgent.
+
+## Examples
+
+### Stream local file
+``` js
+var poster = require('poster');
+
+var options = {
+ uploadUrl: 'http://mysite.com/upload',
+ method: 'POST',
+ fileId: 'file',
+ fields: {
+ 'myfield': 'value',
+ 'myfield2': 'value2'
+ }
+};
+
+poster.post('file.jpg', options, function(err, data) {
+ if (!err) {
+ console.log(data);
+ }
+});
+```
+
+### Stream remote file
+``` js
+var poster = require('poster');
+
+var options = {
+ uploadUrl: 'http://mysite.com/upload',
+ method: 'POST',
+ fileId: 'file',
+ fields: {
+ 'myfield': 'value',
+ 'myfield2': 'value2'
+ }
+};
+
+poster.post('https://www.google.com/logos/2012/addams11-hp.jpg', options, function(err, data) {
+ if (!err) {
+ console.log(data);
+ }
+});
+```
+
+## BYOA (Bring Your Own Agent)
+<pre>
+ npm install tunnel
+</pre>
+
+``` js
+var poster = require('poster');
+var tunnel = require('tunnel'); //only works with 0.6.11+
+var proxyAgent = new tunnel.httpOverHttp({
+ proxy: {
+ host: 'myproxy.com',
+ port: 80
+ }
+});
+
+var options = {
+ uploadUrl: 'http://mysite.com/upload',
+ method: 'POST',
+ fileId: 'file',
+ fields: {
+ 'myfield': 'value',
+ 'myfield2': 'value2'
+ },
+ downloadAgent: proxyAgent
+};
+
+poster.post('https://www.google.com/logos/2012/addams11-hp.jpg', options, function(err, data) {
+ if (!err) {
+ console.log(data);
+ }
+});
+```

0 comments on commit 9806aea

Please sign in to comment.