Hi I am trying to create a dropbox upload button in custom component in retool. This is the code I am using however it only lets me select a file but does not upload it or interact with dropbox:
<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="MY_APP_KEY"></script>
<script>
function uploadFile(files) {
var file = files[0]; // Get the first file from the selected files
var accessToken = 'MY_ACCESS_TOKEN'; // Replace with your access token
var dbx = new Dropbox.Dropbox({ accessToken: accessToken });
dbx.filesUpload({ path: '/' + file.name, contents: file })
.then(function (response) {
console.log('File uploaded successfully!', response);
})
.catch(function (error) {
console.error('Error uploading file.', error);
});
}
</script>
<input type="file" id="fileInput" onchange="uploadFile(this.files)" />
I have entered my access token and app key correctly so I am not sure what the problem is, where am I going wrong?