http.get('http://path/to/image.jpg', function (res) {
var img = '';
res.on('data', function (buff) {
img += buff;
});
res.on('end', function () {
var data = querystring.stringify({
image: img.toString('base64'),
type: 'base64'
});
var opts = {
host: 'api.imgur.com',
path: '/3/image',
method: 'POST',
headers: {
'Authorization': 'Client-ID myId',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': data.length
}
};
var req = https.request(opts, function (res) {
res.on('data', function (buff) {
console.log(buff.toString());
});
});
req.end(data);
});
});
img
URLからダウンロードした文字列です。実行すると、次のようになります。
querystring.js:114
return encodeURIComponent(str);
^
URIError: URI malformed
投稿データをImgurに正しく送信するにはどうすればよいですか?