Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Python
images=db.execute("SELECT encode(img::bytea, 'base64') from images where imgid = 1").fetchall()
    
    
    for i in images:
        for k in i:
            imgdata=b64decode(k)
            filename = 'some_image.jpg'  # I assume you have a way of picking unique filenames
            with open(filename, 'wb') as f:
                f.write(imgdata)


What I have tried:

* Running on http://localhost:9000/ (Press CTRL+C to quit)
127.0.0.1 - - [25/Jun/2018 23:55:06] "GET / HTTP/1.1" 200 -
[2018-06-25 23:55:09,283] ERROR in app: Exception on /download [POST]
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1816, in full_dispatch_request
    return self.finalize_request(rv)
  File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1831, in finalize_request
    response = self.make_response(rv)
  File "C:\ProgramData\Anaconda3\lib\site-packages\flask\app.py", line 1957, in make_response
    'The view function did not return a valid response. The'
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.
Posted
Updated 25-Jun-18 20:11pm
v2
Comments
Mohibur Rashid 25-Jun-18 21:23pm    
Have you open the some_image.jpg by your image-viewer does this work?
What is the relation between what code you posted up there and and your error result?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900