Dropbox Upload Javascript : TypeError: "'fetch' called on an object that does not implement interface Window."

Dropbox Upload Javascript : TypeError: "'fetch' called on an object that does not implement interface Window."

又是一天,又是一个错误!正如您在这段代码中看到的那样,我定义了我的变量文件:

//import { Dropbox } from 'dropbox';

const dbx = new Dropbox.Dropbox({
    accessToken: '<REDACTED>',
    fetch
});

function Dropupload() {
  var fileInput = document.getElementById('file-upload');
  var file = fileInput.files[0];
  dbx.filesUpload({path: '/' + file.name, contents: file})
  .then(function (response) {
      var results = document.getElementById('results');
      results.appendChild(document.createTextNode('File uploaded!'));
      console.log('MISSION COMPLETE');
  })
  .catch(function (error) {
      console.error(error);
      console.log('BETTER LUCK NEXT TIME');
  });
}

我有一个错误说文件未定义,所以我这样做了:

 var file = fileInput; //instead of "var file = fileInput.files[0]; in the previous code"

现在我有一个新的错误:TypeError: "'fetch' called on an object that does not implement interface Window." **uploadRequest** dropbox.js:167

我什至不知道那个错误是什么意思。即使我做了一些研究,我也完全迷路了。我尝试了与互联网上其他人不同的解决方案,但 none 对我有用...

这里是 HTML 顺便说一句:

<!DOCTYPE html>
<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dropbox.js/7.1.0/Dropbox-sdk.js"></script>
    <script src="get_from_cin7.js"></script>
    <!--<script src="Dropupload.js"></script>-->
    <meta charset="utf-8" />
    <title>Dropbox JavaScript SDK</title>
    <!--<link rel="stylesheet" href="/styles.css">-->
</head>
<body>
    <form onSubmit="return Dropupload()">
        <input type="text" id="access-token" placeholder="Access token" />
        <input type="file" id="file-upload" />
        <button type="submit">Submit</button>
    </form>
    <script type = "text/javascript">Dropupload()</script>
</body>
</html>

我要感谢 Greg 提供的这个解决方案,我只是将它作为一个 awnser 发布,以便遇到相同问题的每个人都可以解决它(所有功劳都归 Greg :https://whosebug.com/users/1305693/greg

“至于获取问题本身,请注意您不需要将其传入。有关更多信息,请参见此处:github.com/dropbox/dropbox-sdk-js/blob/master/…。最简单的解决方法就是从你的 Dropbox.Dropbox 构造函数中删除那个 fetch 参数。 – Greg“

谢谢 Greg 的遮阳篷,没有你我可能会浪费很多时间。