Загрузка png в imgur с использованием javascript

Я пытаюсь использоватьJavascript загрузитьpng вImgur, Я использовал код прямо из Imgur APIпример, но я не думаю, что я передаю файл PNG правильно, как я получаю сообщение об ошибке, говорящееfile.type is undefined, Я думаю, что файл в порядке, так как я попробовал это с несколькими различными PNG. Мой код выглядит следующим образом:

<html>
<head>
<script type="text/javascript">
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", "mykey"); // 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);
}
</script>
</head>   

<body>

<button type="button" onclick="upload('test.png')">upload to imgur</button> 

</body>
</html> 

png файлtest.png хранится в том же каталоге, что и мой HTML-файл.

Ответы на вопрос(2)

Ваш ответ на вопрос