Skip to content

Instantly share code, notes, and snippets.

@jcohen
Created August 7, 2012 22:25
Show Gist options
  • Save jcohen/3290044 to your computer and use it in GitHub Desktop.
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)
$ 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
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);
});
@jcohen
Copy link
Author

jcohen commented Aug 7, 2012

Obviously for production code you wouldn't use readFileSync, but you get the idea...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment