如何将图像上传到imgur相册?

时间:2016-06-23 03:03:37

标签: javascript shared-hosting imgur

我想使用javascript将图片上传到自己的相册。

此代码可以将图片上传到imgur,但我不知道如何将其上传到我的相册。

http://jsfiddle.net/FGxGg/57/

$.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);
}});

或者对自己的相册进行图片托管的任何建议?

1 个答案:

答案 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);
}});