0

I'm trying to display PDF files on the page. They are stored on the server. I do not want use public folder as anyone can access it.

I've tried all solution I found, but none seems to work with pdf's:

app.use(express.static('uploads'));
app.use(express.static(path.join(__dirname, 'uploads')));
app.use(express.static(__dirname + '/uploads'));

Strangely enough, I'm able to display images from 'uploads' folder:

<img src='/randomImage.jpg' />

but not pdf's:

<object data='/randomPdf.pdf'></object>

or 

<iframe src='/randomPdf.pdf'></iframe>

I tried to restrict the public folder for not authorized users, but I'm doing something wrong, as it's not working for me:/

app.use(authUsers, express.static('public/uploads'))

Forget to mention that I'm using MongoDB to store ref paths to the files. I fetch all data from DB and then display each pdf on the page.

Thank you in advance.

Martin
  • 25
  • 3
  • 1
    Does this answer your question? [Recommended way to embed PDF in HTML?](https://stackoverflow.com/questions/291813/recommended-way-to-embed-pdf-in-html) – ponury-kostek Nov 20 '22 at 17:47
  • Nope. I tried embedding PDF, but it's not the case. If I move PDF file to `public` folder and add `app.use(express.static('public'))` all files are displayed. I'm not sure why express wont accept different folder. – Martin Nov 20 '22 at 18:06

0 Answers0