cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Pdf file corrupt after downloding

Pdf file corrupt after downloding

advcha
Explorer | Level 3
Go to solution

Hello,

I am using Sharetribe platform that I can't touch the server code but only get access on custom script. So I use jquery ajax to upload and download files to dropbox. The upload process went smooth but the download one has an issue that the downloaded file is corrupt. It can't be opened by any pdf software. I also found the size of the file bigger than the original pdf file in my dropbox. The original pdf file is good and can be opened perfectly.  

Here is the code to download the file 

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

$.ajax({
    url: url,
    type: 'post',
    responseType: 'arraybuffer',
    headers: {
        "Authorization": "Bearer <TOKEN>",
        "Dropbox-API-Arg": JSON.stringify({"path": "/"+filename})
    },
    success: function (data){
        console.log(data);
        //CAN DOWNLOAD PDF BUT CAN'T OPEN IT. FILE PDF IS CORRUPT
        /*var blob = new Blob([data]);
        var aLink = document.createElement('a');
        aLink.href = window.URL.createObjectURL(blob);
        aLink.download = "file_tc.pdf";
        aLink.click();*/
        
        const url = window.URL.createObjectURL(new Blob([data], { type: 'application/pdf' }));
        window.open(url);
    },

    error: function (data){
        console.log(data);
    }
}) 

Anyone can help what's wrong with the above code?

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

[Cross-linking for reference: https://stackoverflow.com/questions/58569036/pdf-file-corrupt-after-downloding ]

In case anyone else comes across this with the same question, it looks like they already found a solution and posted it on StackOverflow here.

View solution in original post

1 Reply 1

Greg-DB
Dropbox Staff
Go to solution

[Cross-linking for reference: https://stackoverflow.com/questions/58569036/pdf-file-corrupt-after-downloding ]

In case anyone else comes across this with the same question, it looks like they already found a solution and posted it on StackOverflow here.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?