cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Check out the Dropbox cheat sheet for getting started in 2021 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

Explorer | Level 3

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

Re: Pdf file corrupt after downloding

Dropboxer

[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

Re: Pdf file corrupt after downloding

Dropboxer

[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

Polls
Are you starting new work habits this year?

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?