2015-02-08 46 views
0

嘗試遠程上傳到imgur時偶爾會出現此錯誤:無法加載資源:服務器響應的狀態爲403(禁止)。但並不是所有的時間和這是可疑的。Imgur API偶爾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(); 
    }; 
+0

你確定你沒有超過他們的費率限制嗎?或者,它可能只是他們最終的一個臨時問題(高服務器負載)。 – Nit 2015-02-08 18:33:07

+0

@Nit我相信我不是好友,我只是測試應用程序,所以我們正在說5-10小時上傳。 – 2015-02-08 18:55:31

回答

0

答案很簡單 - 與在時間Imgur短期內發生了太多的請求阻止他們中的一些。我想這不適用於商業客戶。