cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

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

get_preview returning 'unsupported extension' for pdf/jpeg

Explorer | Level 3

Hello there,

For some reason the get_preview endpoint is returning 'unsupported_extension' even though I'm sending up paths to .jpeg and .pdf file types.

I don't suppose there would be any reason for this?

162600ea24a8590141bcefb57c8274ed

3 Replies 3
Highlighted

Re: get_preview returning 'unsupported extension' for pdf/jpeg

Dropboxer
Dropboxer

The Dropbox API get_preview endpoint does not support retrieving previews for .pdf or .jpeg files. Attempting to do so will result in this error. You can find the supported list of extensions in the documentation here:

https://www.dropbox.com/developers/documentation/http/documentation#files-get_preview

Some of the supported file types will return the preview as PDF, and some will return HTML.

PDF is the output format for many previews anyway, so it isn't supported as an input format. I'll pass this on as a feature request, but if you want to retrieve a .pdf file, you can just use the /2/files/download endpoint:

https://www.dropbox.com/developers/documentation/http/documentation#files-download

For images, you can use /2/files/download as above to get the original data, or /2/files/get_thumbnail to get resized versions:

https://www.dropbox.com/developers/documentation/http/documentation#files-get_thumbnail

Highlighted

Re: get_preview returning 'unsupported extension' for pdf/jpeg

Explorer | Level 3

Hi @Greg-DB,

Sorry for the late reply. I see that when using the /2/files/download endpoint, it seems that it returns the raw data of said file, in my case, a .pdf.

The trouble I am having is being able to download that as an actual .pdf file. It seems that I'm having to create a new Blob object like so:

        get(path)
        .then(res => {
            const downloadFile = (blob, fileName) => {
                const link = document.createElement('a');

                link.href = URL.createObjectURL(blob);
                link.download = fileName;

                document.body.append(link);
                link.click();
                link.remove();

                window.addEventListener('focus', e=>URL.revokeObjectURL(link.href), {once:true});
              };

              downloadFile(new Blob([res]), "example.pdf");

The 'path' endpoint in the get request is just the path of where the file is (handled via backend). The solution above downloads the file, it even has the same amount of pages that the original file has in dropbox, but the pages are blank. This could be a result of the conversion to a Blob.

I don't suppose there is a better way of doing this and not getting a corrupted file?

 

Kind Regards,

Charlie

Highlighted

Re: get_preview returning 'unsupported extension' for pdf/jpeg

Dropboxer
Dropboxer

@ccoplestone I just gave your download handler code a try (with the official Dropbox API v2 JavaScript SDK), and it worked fine for me to download a multiple page PDF without corruption:

    var fileName = "Getting Started.pdf";
    dbx.filesDownload({path: "/" + fileName})
      .then(function(response) {

        var blob = response.fileBlob;  // to match your code; the Dropbox SDK gives the file data as a blob in response.fileBlob

        // your handler code:

        const link = document.createElement('a');

        link.href = URL.createObjectURL(blob);
        link.download = fileName;

        document.body.append(link);
        link.click();
        link.remove();

        window.addEventListener('focus', e=>URL.revokeObjectURL(link.href), {once:true});

        //

      })
      .catch(function(error) {
        console.error(error);
      });

In any case, I do generally just recommend using URL.createObjectURL to get a link to use the downloaded file data blob however desired (e.g., to download) as you already are.

So, I can't say off hand where the issue may be occurring. Can you double check that your source file contains the data you expect it to, and that your PDF viewer is working correctly?

Otherwise, you may need to step through your code in the debugger to see where the data isn't what you expect it to be. If you do find the Dropbox API itself returning something wrong, please let me know so we can investigate.

Polls
Do you know how to organize your files and folders?
We have created a guide on folder best practice, so you can get organized now check it out here.

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?