I have tried this way, but not working for me.Actually what I want is, donwload an image from dropbox and save it in a folder then show it in my UI.But I can't figure it out why this method is not working or which is the right method for downloading image from dropbox using javascript ?
// <--------------dropbox code start here------------->
let options = {
success: function(files) {
console.log("files", files);
let imageLink = files[0].link;
var array = imageLink.split("dl=0");
var splitLink=array[0];
let finalLink=splitLink+"raw=1";
console.log("Final Link",finalLink);
document.getElementById("step-two-rtsp-video").style.display = "none";
document.getElementById('output').style.display = "none";
document.getElementById("take-picture-btn").style.display = "none";
const newImage = document.createElement("img");
newImage.src = finalLink;
document
.getElementById("uploaded-img")
.appendChild(newImage);
var path = files[0].name;
var token = "token";
var url = "https://api-content.dropbox.com/1/files/auto/" + path;
var result;
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
result = xhr.responseText;
console.log(result);
}
}
xhr.open("GET", url, true);
xhr.setRequestHeader("access_token", token);
xhr.setRequestHeader("Authorization", "Bearer " + token);
xhr.send();
},
cancel: function() {
//optional
},
linkType: "preview", // "preview" or "direct"
multiselect: true, // true or false
extensions: ['.png', '.jpg'],
};
var button = Dropbox.createChooseButton(options);
document.getElementById("selectingFileType").appendChild(button);
// <--------------dropbox code end here------------->
Based on the Dropbox API URL with "/1/", I see you're attempting to call Dropbox API v1, which has been retired. You should use Dropbox API v2 instead.
For using Dropbox API v2 with JavaScript, I recommend using the official Dropbox API v2 JavaScript SDK. The README there has information and examples for installing and using it.
To download a file using that, you would use the filesDownload method.