DEV Community

Kaibalya Kar
Kaibalya Kar

Posted on

3

How to Fix "Failed to Load PDF Document" Error on Cloudinary or

How to Resolve "PDF Files Can’t Be Shared Externally" in Cloudinary

If you’re using Cloudinary to upload and share PDF files, you may have run into the annoying error: "PDF files can’t be shared externally." This can be particularly frustrating when you’ve uploaded a PDF and expect to share it publicly, but Cloudinary blocks access by default.

In this post, I’ll walk you through why this happens and how to resolve it step-by-step, so you can successfully share PDF files externally without any hiccups.


Why Does This Happen?

Cloudinary, by default, restricts the delivery of certain file types (like PDFs and ZIP files) for security reasons. This means even if you upload a PDF and get a URL, it won’t be accessible unless you explicitly allow PDF file delivery in your Cloudinary settings. Additionally, the file must be marked as public for it to be accessible via its URL.

Let’s dive into the solution.


Step-by-Step Solution

1. Enable PDF File Delivery in Cloudinary

First, let’s make sure that Cloudinary is set to allow PDF file delivery:

  1. Log in to Cloudinary

    Go to Cloudinary and log in to your account.

  2. Go to Security Settings

    Click on the Settings icon (gear icon) located at the top-right corner of the Cloudinary dashboard.

  3. Scroll to the Security Section

    Scroll down until you find the Security section.

  4. Allow PDF and ZIP File Delivery

    Look for the option labeled PDF and ZIP files delivery. Toggle the switch to Allow delivery of PDF and ZIP files.

  5. Click Save

    After enabling the setting, be sure to click Save to apply the changes.

This will allow Cloudinary to serve PDF files from URLs.


2. Ensure the File is Public

Even after enabling PDF delivery, your file needs to be marked as public to be accessible.

Check the File in Cloudinary Dashboard

  1. Go to the Media Library in your Cloudinary dashboard.

  2. Find the PDF file you uploaded (e.g., resumes/nxx0wzdvdsonnuxgenif.pdf).

  3. Ensure the File is Public

    Confirm that the file is set to Public. If it’s not, you won’t be able to access it through its URL.

Update the Access Mode During Upload

If you’re uploading the file programmatically, you need to ensure that it’s set as public. For example, when uploading a file via JavaScript, add the access_mode: "public" parameter:


javascript
const cloudResponse = await cloudinary.uploader.upload(fileUri.content, {
  resource_type: "raw", // Treat PDF as a raw file
  access_mode: "public", // Make the file publicly accessible
  folder: "resumes",
});

#### **Conclusion**
The "PDF files can’t be shared externally" error on Cloudinary is a common but easily solvable issue. By enabling PDF file delivery in your Cloudinary settings and ensuring your files are marked as public, you can quickly resolve this problem. If you’re still facing issues, double-check your frontend code and consider using an embedded PDF viewer.

I hope this guide saves you the two days I spent debugging this issue. Happy coding! 🚀
Enter fullscreen mode Exit fullscreen mode

Hot sauce if you're wrong - web dev trivia for staff engineers

Hot sauce if you're wrong · web dev trivia for staff engineers (Chris vs Jeremy, Leet Heat S1.E4)

  • Shipping Fast: Test your knowledge of deployment strategies and techniques
  • Authentication: Prove you know your OAuth from your JWT
  • CSS: Demonstrate your styling expertise under pressure
  • Acronyms: Decode the alphabet soup of web development
  • Accessibility: Show your commitment to building for everyone

Contestants must answer rapid-fire questions across the full stack of modern web development. Get it right, earn points. Get it wrong? The spice level goes up!

Watch Video 🌶️🔥

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay