Created
October 24, 2011 02:23
-
-
Save dakatsuka/1308239 to your computer and use it in GitHub Desktop.
Node.jsからHTTPでファイルをアップロードする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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