Announcements
Do you have an idea for Dropbox Paper? Share it with us here!

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

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

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

Reply
Loading...

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

Explorer | Level 3

Hi @Greg K.,

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

Reply
Loading...

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

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.

Reply
Loading...
API Support

Have a question? Our Dropbox Community is here to help you find an answer!
You won’t have to wait too long for a reply, but why not learn more about the Community while you’re here.

Not the right discussion for you? Find out what else our Community has to say about API Support.

Or, search our Help Center for even more.

Who's talking
Top contributors to this post