FriendsOfFlarum / upload

The file upload extension with insane intelligence for your Flarum forum.
https://discuss.flarum.org/d/4154
MIT License
175 stars 94 forks source link

PDF files are not displayed #357

Closed cedpar closed 8 months ago

cedpar commented 8 months ago

Bug Report

Current Behavior PDF files are not displayed

Steps to Reproduce

  1. Upload a PDF file
  2. View conversation
  3. PDF file is not displayed

Expected Behavior Problem with upl-image-preview

Screenshots With Safari :

Capture d’écran 2023-11-08 à 09 29 38 Capture d’écran 2023-11-08 à 09 29 42

With Chrome :

Capture d’écran 2023-11-08 à 09 29 26

Environment

Flarum core: 1.8.3
PHP version: 8.1.22
MySQL version: 10.4.19-MariaDB-1:10.4.19+maria~stretch-log
Loaded extensions: Core, date, libxml, openssl, pcre, sqlite3, zlib, bcmath, bz2, calendar, ctype, curl, dom, hash, fileinfo, filter, ftp, gd, gettext, gmp, json, iconv, SPL, intl, session, ldap, mbstring, standard, pcntl, PDO, mysqlnd, pdo_sqlite, pgsql, Phar, posix, readline, Reflection, imap, SimpleXML, soap, sockets, sodium, pdo_mysql, exif, tidy, tokenizer, xml, xmlreader, xmlwriter, xsl, mysqli, imagick, mailparse, mcrypt, memcached, mongodb, OAuth, raphf, ssh2, timezonedb, uploadprogress, yaz, zip, http
+---------------------+---------+--------+
| Flarum Extensions   |         |        |
+---------------------+---------+--------+
| ID                  | Version | Commit |
+---------------------+---------+--------+
| flarum-tags         | v1.8.0  |        |
| flarum-sticky       | v1.8.0  |        |
| flarum-nicknames    | v1.8.0  |        |
| flarum-lock         | v1.8.0  |        |
| flarum-flags        | v1.8.0  |        |
| kilowhat-audit-free | 1.7.0   |        |
| fof-upload          | 1.4.4   |        |
| fof-links           | 1.2.0   |        |
| fof-geoip           | 1.3.0   |        |
| flarum-statistics   | v1.8.0  |        |
| flarum-mentions     | v1.8.2  |        |
| flarum-markdown     | v1.8.0  |        |
| flarum-lang-french  | v4.17.0 |        |
| flarum-emoji        | v1.8.0  |        |
+---------------------+---------+--------+
Base URL: https://www.rvo95.fr
Installation path: /home/clients/c9af3a0d6b529bf7f121c4804dc1d9fa/sites/rvo95.fr
Queue driver: sync
Session driver: file
Mail driver: smtp
Debug mode: off

Additional Context I tried to change the MIME type but it doesn't work

clarkwinkelmann commented 8 months ago

the upl-image-preview is only designed to preview files that are natively stored as images. In practice it should allow previewing any file that a browser can render inside of an <img src=""> tag. I suppose Safari somehow implemented PDF as a valid IMG source when all other browsers have not.

I am not finding any official documentation on why Safari choose to implement this and how it's supposed to work. The only relevant result seems to be this StackOverflow question but it doesn't lead to any useful information https://stackoverflow.com/questions/70193677/chrome-does-not-allow-me-to-use-pdf-in-img-tag In any case I doubt any browser is actively working to implement such a feature. I don't believe it's part of any web standard existing or in development.

FoF Upload does not have any native way to preview PDFs. Another extension could provide a new template that does. An easy solution would be to render the PDF in an iframe as it would take advantage of the browser ability to render a PDF viewer, but this would be dangerous to safeguard against XSS vectors. A safer solution would be an extension that implements a server-side rendering of a preview image and returns it to the frontend in a new template. I doubt either of these options would be added to FoF Upload directly at this moment as they require significant work and increase the maintenance burden.

If you still believe this is a bug with an existing FoF Upload feature, feel free to re-open the issue with more details.