You're send string representation of read
method.
Instead call the read
method by appending ()
:
self.wfile.write(content.read())
If the file is huge, file.read()
make a problem because read()
load file content into memory. To prevent that, use shutil.copyfileobj
:
import shutil
...
self.send_response(200)
self.send_header('Content-type', 'image/jpeg')
self.end_headers()
with open(content_path, 'rb') as content:
shutil.copyfileobj(content, self.wfile)