admin管理员组文章数量:1320773
I'm building a funny Chrome-Experiment. The Mustache Mirror! / I want to use the Imgur API V3 to upload an image from te canvas to Imgur and then show the link, but I really don't know how. All the working examples I find are using the V2 API...
I use canvas.toDataURL:
var dataURL = canvas.toDataURL("image/png");
return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
I'm building a funny Chrome-Experiment. The Mustache Mirror! http://sjoerddijkstra.nl/cam/ I want to use the Imgur API V3 to upload an image from te canvas to Imgur and then show the link, but I really don't know how. All the working examples I find are using the V2 API...
I use canvas.toDataURL:
var dataURL = canvas.toDataURL("image/png");
return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
Share
Improve this question
edited Jul 23, 2013 at 8:51
rid
63.6k31 gold badges157 silver badges197 bronze badges
asked Jul 23, 2013 at 8:46
Sjoerd DijkstraSjoerd Dijkstra
411 silver badge3 bronze badges
1
- Hillarious application! – samuraiseoul Commented Dec 11, 2013 at 4:23
1 Answer
Reset to default 11Imgur documentation is kinda poor IMO but after asking around in SO I found this to work:
try {
var img = document.getElementById('myCanvas').toDataURL('image/jpeg', 0.9).split(',')[1];
} catch(e) {
var img = document.getElementById('myCanvas').toDataURL().split(',')[1];
}
$.ajax({
url: 'https://api.imgur./3/image',
type: 'post',
headers: {
Authorization: 'Client-ID <CHANGE_THIS_TO_BE_YOUR_CLIENT_ID>'
},
data: {
image: img
},
dataType: 'json',
success: function(response) {
if(response.success) {
window.location = response.data.link;
}
}
});
Replace <CHANGE_THIS_TO_BE_YOUR_CLIENT_ID>
with the client id you get when you register your app here (I picked the "anonymous usage without user authorization" option).
本文标签: Upload a canvas image to imgur (api v3) with javascriptStack Overflow
版权声明:本文标题:Upload a canvas image to imgur (api v3) with javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742090346a2420227.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论