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

R-son

Another day, another error! I defined my variable file as you can see in this code :

//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');
  });
}

And I had an error saying that file was undefined, so i did this :

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

And now I have a new error : TypeError: "'fetch' called on an object that does not implement interface Window." **uploadRequest** dropbox.js:167

I don't even know what that error means. I'm totally lost even though I did some research. I tried different solutions from other people on the internet but none have worked for me...

Here's the HTML by the way :

<!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>
R-son

I want to thank Greg for this solution, I'm just posting it as an awnser so everyone who has the same problem can resolve it (All the credits go to Greg : https://stackoverflow.com/users/1305693/greg)

"As for the fetch issue itself, note that you don't need to pass that in. See here for more information: github.com/dropbox/dropbox-sdk-js/blob/master/… . The easiest fix for that is to just remove that fetch parameter from your Dropbox.Dropbox constructor. – Greg"

Thank you Greg for your awnser, I would've probably wasted a lot of time without you.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

upload file to dropBox using /files_put javascript

From Dev

Upload blob to dropbox from client-side javascript

From Dev

Upload blob to dropbox from client-side javascript

From Dev

Dropbox partial upload

From Dev

Upload a file into dropbox folder

From Dev

Upload file to Dropbox through VBA

From Dev

Chunk upload using Dropbox API

From Dev

Dropbox Sync API cancel upload

From Dev

Upload to dropbox using Restsharp PCL

From Dev

android dropbox api file upload

From Dev

Selecting a dropbox folder in Javascript

From Dev

TypeError: Upload.upload is not a function

From Dev

Upload files to the specific Dropbox account on Android

From Dev

upload file to my dropbox from python script

From Dev

Dropbox direct upload files from browser

From Dev

How to upload complete folder to Dropbox using python

From Dev

Dropbox upload slows internet speed drastically

From Dev

Control Dropbox upload rate on the command line

From Dev

dropbox access token for others to upload to my folder

From Dev

Share (upload) a created PDF to Dropbox in iOS

From Dev

Dropbox file upload automatically using php

From Dev

Upload Files To Dropbox In ASP.Net

From Dev

Is it possible to upload a file to dropbox when user is not logged in?

From Dev

Upload/download a whole folder with dropbox api core

From Dev

Is there a way to tell if a Dropbox chunk upload commit was successful?

From Dev

android upload xml file to google drive or dropbox

From Dev

Dropbox.Api failing to upload large files

From Dev

File Upload to Dropbox from FORM with PHP

From Dev

Upload zipped file to Dropbox using C#