Skip to content

Instantly share code, notes, and snippets.

@dakatsuka
Created October 24, 2011 02:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dakatsuka/1308239 to your computer and use it in GitHub Desktop.
Save dakatsuka/1308239 to your computer and use it in GitHub Desktop.
Node.jsからHTTPでファイルをアップロードする
var fs = require('fs')
var request = require('request')
fs.readFile('/tmp/photo.jpg', function(err, data) {
request.post({
method: "POST",
uri: "http://localhost:3000/users/1/photo",
multipart: [
{
'Content-Disposition': 'attachment; name="data"; filename="data"',
'Content-Type': 'image/jpeg',
'Content-Length': data.length,
'body': data
}
]
}, function(error, response, body) {
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment