Created
August 7, 2012 22:25
-
-
Save jcohen/3290044 to your computer and use it in GitHub Desktop.
Upload photos using the Flickr API from node (and Mikeal's request using oauth and multipart)
This file contains hidden or 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
$ time node upload.js | |
Error: null | |
Body: <?xml version="1.0" encoding="utf-8" ?> | |
<rsp stat="ok"> | |
<photoid>7735964772</photoid> | |
</rsp> | |
real 0m5.517s | |
user 0m0.106s | |
sys 0m0.028s |
This file contains hidden or 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"); | |
var oauth = { | |
"consumer_key" : CONSUMER_KEY, | |
"consumer_secret" : CONSUMER_SECRET, | |
"token" : AUTH_TOKEN, | |
"token_secret": AUTH_SECRET | |
}; | |
request.post({ | |
"url" : "http://api.flickr.com/services/upload/", | |
"oauth" : oauth, | |
"headers" : { | |
"content-type" : "multipart/form-data" | |
}, | |
"multipart" : [ | |
{ | |
"Content-Disposition" : 'form-data; name="photo"; filename="/Path/to/some/photo.jpg"', | |
"Content-Type" : "image/jpeg", | |
"body" : fs.readFileSync("/Path/to/some/photo.jpg") | |
} | |
] | |
}, function(error, response, body) { | |
console.log("Error: ", error); | |
console.log("Body: ", body); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Obviously for production code you wouldn't use readFileSync, but you get the idea...