0

Hi im trying to download a specific file in dropbox using ajax the response of the console was XHR finished loading: GET "https://content.dropboxapi.com/2/files/download".

But the second response was this

%PDF-1.4
%����
428 0 obj
<</Linearized 1/L 905827/O 431/E 99933/N 10/T 897151/H [ 1556 680]>>
endobj

xref
428 63
0000000016 00000 n
0000002418 00000 n
0000002599 00000 n
0000002635 00000 n
0000003049 00000 n
0000003204 00000 n
0000003357 00000 n
0000003511 00000 n
0000003665 00000 n
0000003819 00000 n
0000003973 00000 n
0000004126 00000 n
0000004280 00000 n
0000004434 00000 n
0000004586 00000 n
0000004741 00000 n
0000004896 00000 n
0000005051 00000 n
0000005190 00000 n
0000005329 00000 n
0000005468 00000 n
0000005607 00000 n
0000005746 00000 n
0000006256 00000 n
0000006370 00000 n
0000006802 00000 n
0000007313 00000 n
0000017758 00000 n
0000026875 00000 n
0000037078 00000 n
0000046557 00000 n
0000055897 00000 n
0000066128 00000 n
0000066620 00000 n
0000067209 00000 n
0000067661 00000 n
0000067749 00000 n
0000068102 00000 n
0000068646 00000 n
0000069067 00000 n
0000078729 00000 n
0000088722 00000 n
0000088794 00000 n
0000088866 00000 n
0000088938 00000 n
0000089010 00000 n
0000089082 00000 n

And some randomize character I was wondering I just convert it to text?

this is my ajax response

var url = 'https://content.dropboxapi.com/2/files/download';

$.ajax({
  url: url,
  type: 'GET',
  headers: {
   "Authorization": "Bearer AccessToken",
   "Dropbox-API-Arg": '{"path": "/Get Started with Dropbox.pdf"}'
  },
  success: function (data){
    console.log(data);
   },

  error: function (data){
    console.log(data);
  }
})
Karthick Nagarajan
  • 1,327
  • 2
  • 15
  • 27
  • https://stackoverflow.com/questions/39139828/download-a-file-and-redirect-it-to-another-page-via-ajax try with this – Kumar Rakesh Jan 27 '17 at 07:54

2 Answers2

0

Ajax does not support cross domain calls. If the domain that you are using to host the ajax script is different than the ajax url domain then your code wont work.

rde
  • 53
  • 7
  • So how can I download my file? –  Jan 27 '17 at 09:27
  • Check if the path that you are mentioning in "Dropbox-API-Arg" is correct. Also I hope you are replacing "AccessToken" with the actual access token value. – rde Jan 27 '17 at 10:00
  • yes i write only accessToken for security purpose.. and I think my Dropbox-api-arg is correct because thats the path of the file –  Jan 31 '17 at 01:32
0

Maybe I misunderstood but do you want to parse the pdf result ?

To create a download link to the dropbox file you can do something like this :

success: function(data) {
  var file = new Blob([data]);
  var aLink = document.createElement('a');
  aLink.href = window.URL.createObjectURL(blob);
  aLink.download = "file_" + new Date() + ".pdf";
  aLink.click();
}
Quentin Roger
  • 6,410
  • 2
  • 23
  • 36
  • Im sorry for the poor details.. My ajax call is inside of a button and any file will do –  Jan 27 '17 at 08:02