0

I'm looking to display a blob stored in a MySQL table within an HTML, using python-flask. But i am getting the broken image icon on the webpage when i run the code. The string data renders just fine, but not the blob. The web developer tool is indicating a 404 error when attempt to grab the blob resource, but i can't seem to make much of it. Looking for some help.

My Python code is:

@EMR.route("/apple")
def apple_luv():
    t0 = gold.query.filter_by(patient_id=101).first()
    tx = t0
    return render_template("apple.html", t1=tx)

and HTML is shown below (FYI: tried a few syntaxes with the img tag since i was unsure)

<body>
    {{t1.patient_fname}} | {{t1.patient_lname}} | {{t1.patient_addr}}
    <br><br><br>
    <img src="{{t1.patient_pic}}" />    
    <br><br><br>
    <img src={{t1.patient_pic}} />
    <br><br><br>
    <img src="{{t1.patient_pic}}" > 
    <br><br><br>
    <img src={{t1.patient_pic}} >   
</body>

See the attachments for what my data looks like in MySQL DB, and the webpage outcome as well.

patient 101 patient 101 - blob info 01 patient 101 - blob info 02 patient 101 - blob info 03 apple.html browser tool output

user15771504
  • 67
  • 1
  • 7
  • 1
    You have to create a separate endpoint, that will serve the image content with the right content-type header set. An example can be found at https://stackoverflow.com/a/11017839/3929826 – Klaus D. Jul 16 '21 at 20:50
  • Thanks Klaus - It would help to get a breakdown of the steps involved (from my perspective) i.e. packages to import, logic flow etc. – user15771504 Jul 16 '21 at 21:05
  • 1
    How about you start with the steps I gave, based on the information from the other question? And if you get stuck tell us where and show us the code. Here on Stack Overflow it is expected that you participate as much as possible. – Klaus D. Jul 16 '21 at 21:21
  • Thanks for your input Klaus. The link you provided seem to have multiple approaches (io, base64, send_file etc.). Not looking to get confused here. I'll take in additional feedback on here - hopefully, a simpler approach will emerge to this what seems to be a familiar issue. – user15771504 Jul 16 '21 at 21:34

0 Answers0