One month down in 2025: How are your resolutions coming along? Check out how to get back on track here.
Forum Discussion
ccoplestone
6 years agoExplorer | Level 3
get_preview returning 'unsupported extension' for pdf/jpeg
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?
- Greg-DB
Dropbox Staff
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
- ccoplestoneExplorer | 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
- Greg-DB
Dropbox Staff
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.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.5,950 PostsLatest Activity: 46 minutes ago
If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!