Skip to navigation
Return a picture with falcon python
30.07.19
def on_get(self, req: falcon.Request, resp: falcon.Response,name): # http://foo.com/img/14B-1.6-4.png # http://127.0.0.1:8062/img/14B-1.6-4.png style = name[:-4] if style: url = '{}/styles/{}'.format(self.cb['host'],style) r = requests.get(url,auth=(self.cb['user'],self.cb['pass'])) if r.status_code == 200: picture = r.json()['picture'] path = '{}{}'.format(self.pic_path,picture) i = Image.open(path) o = io.BytesIO() i.save(o, format='PNG',dpi=(300,300)) resp.content_type = 'image/png' resp.append_header('Content-Disposition','attachment; filename="{}"'.format(name)) resp.body = o.getvalue() resp.status = falcon.HTTP_200
https://falcon.readthedocs.io/en/stable/user/tutorial.html
Reply
Anonymous
show the image in the browser without download #resp.append_header('Content-Disposition','attachment; filename="{}"'.format(name))
30.07.19
Reply
Anonymous
Information Epoch 1745984490
Small is beautiful.
Home
Notebook
Contact us