XWiki PDF Handling: Encrypting Downloads While Allowing Previews

Hello everyone,
I am using XWiki(Xwiki 15.6) on Kubernetes and I have a specific requirement. I want to be able to preview PDF files via the web tab, but when downloading, I need to encrypt the files.
Work completed so far:

  • some PDF attachment exist.
  • I have written an encryption program (called Crypt-Gateway).
  • I am using Istio’s Envoy Filter as a request controller (it can access request headers and parameters to perform redirection or allow requests).

However, I am currently facing two problems:

  • I cannot distinguish between a download and preview from request headers and parameters. Therefore, I cannot decide whether to encrypt the file.
  • I noticed that when previewing the interface and directly downloading my file, the file is downloaded without any network request.(No further requests are made to my XWiki, so if someone clicks preview first and then downloads, my encryption program cannot encrypt the file.)

I would like to know:

  • Does XWiki already have similar functionality? I understand that the Attachment section in XWiki mentions forced download (force-download) and whitelist-related content, but I believe that does not meet my needs of both PDF preview and encryption.
  • Is there something wrong with my approach or logic?

I am not a native English Speaker. If there are any issues with my expression, please let me know so I can make corrections and additions at any time.
Any advice or tips will be appreciated.

A preview is using the “preview” action in the URL while a download is using the “download” action. See:

Hope it helps

1 Like

Thank you very much for your reply, and I apologize for my delayed response. I have temporarily achieved this functionality through Macro + OnlyOffice. I created an HTML page that accepts a file URL parameter and uses OnlyOffice (OO) to display it. Additionally, I set all files in XWIKI to be downloadable (they are redirected through K8S to our internal encryption application, which returns an encrypted file). For previewing, OnlyOffice is used with download and other functions disabled.

And your response will likely help others with similar needs, thank you very much again.