gpt4 book ai didi

javascript - Imgur API 偶尔出现 403 Forbidden?

转载 作者:行者123 更新时间:2023-11-28 07:37:55 28 4
gpt4 key购买 nike

尝试远程上传到 imgur 时,我偶尔会遇到此错误:无法加载资源:服务器响应状态为 403(禁止)。但并非总是如此,这是值得怀疑的。

这是我的代码:

/* Drag and drop */
window.ondragover = function(e) {
e.preventDefault();
};

window.ondrop = function(e) {
e.preventDefault();
upload(e.dataTransfer.files[0]);
};

function upload(file) {
document.getElementById("view1").style.display = "none";
document.getElementById("loading").style.display = "inline";
var imageLink = "";
/* Is the file an image? */

if (!file || !file.type.match(/image.*/)) return;
document.body.className = "uploading";
var fd = new FormData();
fd.append("image", file); // Append the file
fd.append("key", "6528448c258cff474ca9701c5bab6927"); // The key
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://api.imgur.com/2/upload.json");
xhr.onload = function() {
var link = JSON.parse(xhr.responseText).upload.links.imgur_page;

document.getElementById("loading").style.display = "none";

document.querySelector("#link").href = link;
document.querySelector("#link").innerHTML = link;
var imageLink = ""+document.querySelector("#link").innerHTML.replace("http://imgur.com/", "http://i.imgur.com/")+".jpg";

/* Image Preview */
document.getElementById("result").style.display = "inline";
document.getElementById("link-to-image").style.background = "url(" + imageLink + ") center center no-repeat";
document.body.className = "uploaded";
};

/* Send the formdata */
xhr.send(fd);
/* Remove the button */
document.getElementById("button").remove();
};

最佳答案

答案很简单 - 由于短时间内发生的请求过多,Imgur 阻止了其中一些请求。我想企业客户的情况并非如此。

关于javascript - Imgur API 偶尔出现 403 Forbidden?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28397183/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com