2

我在一个论坛上做志愿者,该论坛的成员大多是老年人,因此可能会受到技术挑战。我们过时的冷聚变论坛软件不允许上传照片,但允许从 IMGUR 等外部站点嵌入。我正在寻找一个基于 Javascript 的简单拖放上传器,并在https://hacks.mozilla.org/2011/03/the-shortest-image-uploader-ever/上找到了 Paul Rouge 提供的免费使用简单脚本.

function upload(file) {

// file is from a <input> tag or from Drag'n Drop
// Is the file an image?

if (!file || !file.type.match(/image.*/)) return;

// It is!
// Let's build a FormData object

var fd = new FormData();
fd.append("image", file); // Append the file
fd.append("key", "6528448c258cff474ca9701c5bab6927");
// Get your own key: http://api.imgur.com/

// Create the XHR (Cross-Domain XHR FTW!!!)
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://api.imgur.com/2/upload.json"); // Boooom!
xhr.onload = function() {
// Big win!
// The URL of the image is:
JSON.parse(xhr.responseText).upload.links.imgur_page;
}
// Ok, I don't handle the errors. An exercice for the reader.
// And now, we send the formdata
xhr.send(fd);
}

该脚本使用他的 API v2 客户端 ID 可以正常工作,但我无法使用 IMGUR API v3 让它与我的客户端 ID 一起使用?尝试使用“Authentication”“Client-ID”进行更新,将 IMGUR 路径设置为“ https://api.imgur.com/3/image ”等,但没有运气?

任何人都知道如何使这项工作?或者,知道另一个类似的 Javascript IMGUR 上传器(客户端)吗?我为不擅长编写脚本而道歉?

感谢你的协助。

4

0 回答 0