svenstaro/miniserve

Allow to preview pdf instead of download

GopherJ opened this issue ยท 9 comments

Allow to preview pdf instead of download

You mean you'd like to view PDFs directly in the browser instead of having the browser offer you to download the PDF?

SF73 commented

I don't know if it refers to this, but as mentionned in #634, it would be nice to have Content-Disposition:inline for pdf files.
That way, it would be possible to view them without having to download them.

I don't know if the issue should be adressed here or in actix-files here

I would like this too. I am trying miniserve --header "Content-Disposition:inline" and I think it is getting overwritten.

@svenstaro yes, like mozilla's pdf.js, users can choose if they would like to download or not later

I think the overwriting might be done by actix components. Can someone check out the code path? I'm not sure when I can get to it.

I applied the following patch in actix-files to make it worked

diff --git a/actix-files/src/named.rs b/actix-files/src/named.rs
index d7795ba7..308cf702 100644
--- a/actix-files/src/named.rs
+++ b/actix-files/src/named.rs
@@ -134,7 +134,9 @@ impl NamedFile {
                 mime::IMAGE | mime::TEXT | mime::AUDIO | mime::VIDEO => DispositionType::Inline,
                 mime::APPLICATION => match ct.subtype() {
                     mime::JAVASCRIPT | mime::JSON => DispositionType::Inline,
-                    name if name == "wasm" || name == "xhtml" => DispositionType::Inline,
+                    name if name == "wasm" || name == "xhtml" || name == "pdf" => {
+                        DispositionType::Inline
+                    }
                     _ => DispositionType::Attachment,
                 },
                 _ => DispositionType::Attachment,

Could you post the patch? If it gets merged, we will automatically benefit. Might need to make it configurable though.