问题描述
//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');
});
}
@H_404_4@
var file = fileInput; //instead of "var file = fileInput.files[0]; in the prevIoUs code"
@H_404_4@
现在我有一个新错误:TypeError: "'fetch' called on an object that does not implement interface Window." **uploadRequest** dropBox.js:167@H_404_4@
我什至不知道那个错误是什么意思。即使做了一些研究,我也完全迷失了。我尝试了与互联网上其他人不同的解决方案,但没有一个对我有用...
以下是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>
@H_404_4@
解决方法
我要感谢Greg的解决方案,我只是将其发布为遮阳篷,以便每个有相同问题的人都可以解决(所有功劳归于Greg:https://stackoverflow.com/users/1305693/greg)
“关于获取问题本身,请注意,您不需要传递该信息。有关更多信息,请参见此处:github.com/dropbox/dropbox-sdk-js/blob/master/…。最简单的修复方法为此,只需从Dropbox.Dropbox构造函数中删除该获取参数。– Greg“
谢谢格雷格(Greg)的遮阳篷,如果没有你,我可能会浪费很多时间。