# Display large PDF files in file preview

**URL:** <https://community.forestadmin.com/t/display-large-pdf-files-in-file-preview/7586>\
**Category:** Help me!\
**Created:** [October 30, 2024, 3:12pm UTC](https://community.forestadmin.com/t/display-large-pdf-files-in-file-preview/7586 "2024-10-30T15:12:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbescoyez](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jbescoyez/32/7444_2.png) [@jbescoyez](https://community.forestadmin.com/u/jbescoyez)\
**Post date:** [October 30, 2024, 3:12pm UTC](https://community.forestadmin.com/t/display-large-pdf-files-in-file-preview/7586/1 "2024-10-30T15:12:48Z")

</div>

## Feature(s) impacted

Previewing large PDF file (I my case 1,7MB)

## Observed behavior

I tried 2 approaches:

### A) Send file as data-url:

 ![CleanShot 2024-10-30 at 16.03.25@2x](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/6/63d8ad4b28e274181c878a5bd63542f33f444297.png)

And I get this result:

 ![CleanShot 2024-10-30 at 16.05.18@2x](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/3/35755c2174d8556f153d85ef5e0e317b1c79b8eb.png)

### B) Send the S3 signed-URL to the file

 ![CleanShot 2024-10-30 at 16.07.35@2x](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/3/3c31b9a04e7d5c99ee9c127c60703bf6fe96b662.png)

And I get the following error (`net::ERR_BLOCKED_BY_ORB`) in the browser:

 ![CleanShot 2024-10-30 at 16.08.57@2x](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/4/46c8cd7af63b2f784bd501d8dd1a055ff8bda965.png)

Here are my bucket CORS:

 ![CleanShot 2024-10-30 at 16.10.10@2x](https://europe1.discourse-cdn.com/flex013/uploads/forest/original/2X/6/6f234eb1059dd058acc51245c00b41f28224e65c.png)

When I copy/paste the URL and request it from another tab in the browser (or CURL it) I get the file without issues.

## Expected behavior

Having the PDF displayed

## Context

- Project name: Finance X
- Team name: Operations
- Environment name: Development
- Agent technology: rails
- Agent (forest package) name & version: forest\_liana (9.3.16)
- Database type: postgresql

---

<div class="post-metadata">

**Author:** ![nbouliol](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nbouliol/32/5777_2.png) [@nbouliol](https://community.forestadmin.com/u/nbouliol)\
**Post date:** [October 30, 2024, 4:08pm UTC](https://community.forestadmin.com/t/display-large-pdf-files-in-file-preview/7586/2 "2024-10-30T16:08:38Z")

</div>

Hello @jbescoyez

We only support preview for files with a maximum size of 1.5 Mo

I will add this to the documentation

---

<div class="post-metadata">

**Author:** ![jbescoyez](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jbescoyez/32/7444_2.png) [@jbescoyez](https://community.forestadmin.com/u/jbescoyez)\
**Post date:** [October 30, 2024, 4:34pm UTC](https://community.forestadmin.com/t/display-large-pdf-files-in-file-preview/7586/3 "2024-10-30T16:34:33Z")

</div>

What is the reason?

If the file is downloaded from S3, it does not impact performance or bandwidth.

---

<div class="post-metadata">

**Author:** ![jbescoyez](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jbescoyez/32/7444_2.png) [@jbescoyez](https://community.forestadmin.com/u/jbescoyez)\
**Post date:** [October 31, 2024, 8:27am UTC](https://community.forestadmin.com/t/display-large-pdf-files-in-file-preview/7586/4 "2024-10-31T08:27:25Z")

</div>

Update:  
I have tested the second approach (with S3 URLs) in Safari and it works in the file viewer for files \> 1.5MB.

The remaining question is: “why does Chrome blocks access to S3 signed URLs”. I am unable to find an answer on the web.

---

<div class="post-metadata">

**Author:** ![jbescoyez](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/jbescoyez/32/7444_2.png) [@jbescoyez](https://community.forestadmin.com/u/jbescoyez)\
**Post date:** [October 31, 2024, 9:57am UTC](https://community.forestadmin.com/t/display-large-pdf-files-in-file-preview/7586/5 "2024-10-31T09:57:29Z")

</div>

I managed to solve the issue. Here is the full story:

- The S3 signed URLs do not mention the extension of the file type (only the object id)
- The file preview widget choose the HTML tag for the embedded content depending on the filename.
- By default, the file preview widget would choose the `<img>` tag
- Firefox and Chrome block the content of the file when the browser try to display a PDF in an `<img>`tag. (`ERR_BLOCKED_BY_ORB` for Chrome and `NS_BINDING_ABORTED` for Firefox)

I mitigated this behavior by using [ActiveStorage redirect mode](https://edgeguides.rubyonrails.org/active_storage_overview.html#redirect-mode) for serving files instead of a direct link to S3.

This would be useful to mention in the documentation that the extension of the file in the URL has to match the file type.
