0

I would like to open PDF file inside my Django application, something like file:///...

I know that a lot of posts state that this should not be done because security reason, and that google block this calls with error. link.

But, I know that:

  1. I saw this behaviour so, I know it can be done somehow
  2. I don't have security risk, because application is internal, not connected to the internet (available over lan)
  3. Protocol file:/// wouldn't exist if there wouldn't be a way to use it.

I also read somewhere that you need to put file in 'public' if you would like to access it via this method. Do anyone know how to do this?

Marko Zadravec
  • 8,298
  • 10
  • 55
  • 97

1 Answers1

0

file:// is only available for browsers, not servers.

If you want your Django application to access local files, you need to upload them to the Django application server (at which point they're not really local).

(If the application server is running on the same machine as the client, naturally you can use Python's usual file functions to read the local file system.)

JavaScript can also access local files and process them in-browser as long as they're manually selected by the user.

AKX
  • 152,115
  • 15
  • 115
  • 172
  • Thank you for your reply. How do I upload files to Django application server (in witch folder ) - and how to access them then. I don't wan't that use select the file, but to click on button with manuals and get manual pdf (not as download but for reading ) – Marko Zadravec Jul 02 '18 at 09:29
  • If the files don't change often, just add them as static files. https://docs.djangoproject.com/en/2.0/howto/static-files/ – AKX Jul 02 '18 at 09:46
  • how to achieve something like this : http://www.grdjournals.com/uploads/article/GRDJE/V01/I06/0084/GRDJEV01I060084.pdf – Marko Zadravec Jul 02 '18 at 09:54
  • 1
    That's just a PDF file that happens to open in the browser. You can attempt to force inline viewing of PDFs using the `Content-Disposition` HTTP header. – AKX Jul 02 '18 at 13:24