How to save a image file on a Postgres database?

前端 未结 5 1284
后悔当初
后悔当初 2021-01-31 06:21

For learning purposes, I\'m creating a site using Python+Flask. I want to recover an image from database and show it on screen. But one step at a time.

I have no idea ho

5条回答
  •  情书的邮戳
    2021-01-31 06:33

    I hope this will work for you.

    import Image
    import StringIO
    im = Image.open("file_name.jpg") # Getting the Image
    fp = StringIO.StringIO()
    im.save(fp,"JPEG")
    output = fp.getvalue() # The output is 8-bit String.
    

    StringIO Image

提交回复
热议问题