Your workflow is unique 👨💻 - tell us how you use Dropbox here.
Forum Discussion
Yariazen1
6 years agoExplorer | Level 3
Dropbox API upload
var file = new File([data], filename, { type: "type/plain", }); var ACCESS_TOKEN = access token; xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload', true); xhr.setRequestHead...
Yariazen1
6 years agoExplorer | Level 3
Actually that's not the problem after all
Greg-DB
Dropbox Community Moderator
6 years ago[Cross-linking for reference: https://stackoverflow.com/questions/55451478/xhrhttprequest-to-dropbox-xhr-failed-loading-options ]
The https://content.dropboxapi.com/2/files/upload endpoint is still the correct way to upload files (smaller than 150 MB). I just tried it, and it is working for me. If something's not working for you, be sure to print out the response body for an error message.
Here's a simple example of using it via a XMLHttpRequest in Javascript.
<!DOCTYPE html>
<html>
<body>
<form>
<input id="fileInput" type="file" name="file" onchange="uploadFile">
</form>
<script type="text/javascript">
var fileInput = document.getElementById('fileInput')
fileInput.onchange = function(event) {
accessToken = "ACCESS_TOKEN_HERE";
// * file = file object selected in the file widget.
var file = fileInput.files[0];
var xhr = new XMLHttpRequest();
xhr.onload = function() {
if (xhr.status === 200) {
var fileInfo = JSON.parse(xhr.response);
console.log(fileInfo);
}
else {
var errorMessage = xhr.response || 'Unable to upload file';
console.log(errorMessage);
}
};
xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload');
xhr.setRequestHeader('Authorization', 'Bearer ' + accessToken);
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
path: '/' + file.name
}));
xhr.send(file);
};
</script>
</body>
</html>
About Dropbox API Support and Feedback
Get help with the Dropbox API from fellow developers and experts.
The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X, Facebook or Instagram.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!