Working Example
是,当用户添加文件,使用http://api.imgur.com/examples:
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:
document.getElementById('TextAreaId').innerHTML = 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);
}
来源
2011-08-25 20:23:24
Joe
你为什么要允许用户下载他们刚刚上传的文件。我可以理解上传/存储供以后使用,但现在上传并提供可能有点多余。 –
@Marc B:你的意思是像imageshack和相关? – Konerak
这是因为当我在我的公司制作票时,我喜欢通过屏幕截图或文件ID ......我们不允许在此过程中使用第三方程序或网站。 – Bulvak