Home > Software design >  Is there a way to render files from a MySQL database into a website?
Is there a way to render files from a MySQL database into a website?

Time:02-14

I'm tasked to build a web document management system where files (PDFs, and perhaps images) will be uploaded and viewed later in the website. Currently what I have is the upload goes into MySQl workbench, in a longblob data type field.

I want to render the files on the webpage somewhat like research journal websites that have a PDF viewer of some sort in their pages.

I tried selecting the File value off the database table, and placing it in iframe's src attribute but it does not do anything. Though iframe does render the file if given a file address on my computer.

enter image description here

CodePudding user response:

You cannot save file in mysql! You must save the file somewhere on your host then give the files links to the mysql and for rendering it you should load files from their links.

CodePudding user response:

The src attribute contains an URL, not file content. You should make the src attribute name an URL that calls a code handler. Then develop the code for that handler, which loads the content from the database and returns it as the response, after setting the response header for "Content-Type: application/pdf".

  • Related