3

I tried to download a file from Dropbox using Core Api with javascript. Here is the method I have written.

function downloadFile(path) {
    var url = "https://api-content.dropbox.com/1/files/auto/"+path;
    var result;
    var xhr = new XMLHttpRequest();
    xhr.open("POST", url, false);
    xhr.onreadystatechange = function() {    
        if (xhr.readyState === 4 && xhr.status === 200) {
            result = xhr.responseText;
        }
    }
    xhr.send(path);
}

But I am always getting the status as 400. Don't know whats wrong. I got this below HTML as response.

<html>
<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<center>The plain HTTP request was sent to HTTPS port</center>
<hr><center>nginx</center>
</body>
</html>

Edit 1 :

  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;
        }
    }
    xhr.open("GET", url, true);
    xhr.setRequestHeader("access_token",token);
    xhr.send();
16
  • seems headers is missing in request
    – manivannan
    Commented Jul 27, 2015 at 5:36
  • which header do i need to add ?? Commented Jul 27, 2015 at 5:37
  • Where in your code are you handling HTTPS? It likely isn't enough to just add in an HTTPS URL and have the API accept it.
    – AMR
    Commented Jul 27, 2015 at 5:43
  • 3
    Here's a jsfiddle with a version of your code that works for me: jsfiddle.net/qfwf7uhp Here's what I get: dropbox.com/s/9xjjh9ygkknrf37/… Does that work for you if you put in your path and access token?
    – Greg
    Commented Jul 30, 2015 at 6:04
  • 1
    Now i am getting the correct response... We are using wakanda ssjs framework. it is having both client side and serverside javascript. We tried from server side and doesn't work. Now calling from client side, it works perfctly. Thanks for your support. Thank you all for your support. :-D Commented Jul 30, 2015 at 6:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.