我想使用javascript将图片上传到自己的相册。
此代码可以将图片上传到imgur,但我不知道如何将其上传到我的相册。
$.ajax({
url: "https://api.imgur.com/3/upload",
type: "POST",
datatype: "json",
data: {image: imgUrl},
success: showMe,
error: showMe,
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Client-ID " + clientId);
}});
或者对自己的相册进行图片托管的任何建议?
答案 0 :(得分:2)
Imgur的所有终结点都有detailed API documentation,包括 Image Upload 。
根据文档,您可以为要上传的相册的album
提供id
参数。因此,请更改您的数据以包含它:
var clientId = ""; // Your client Id
var imgUrl = "http://i.imgur.com/l5OqYoZ.jpg";
var albumId = 'ABC123'; // Your owned album id
$.ajax({
url: "https://api.imgur.com/3/upload",
type: "POST",
datatype: "json",
data: {image: imgUrl, album: albumId},
success: showMe,
error: showMe,
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Client-ID " + clientId);
}});