I’m fairly new to web applications and I’m trying to write a web.py server that will allow me to download an image. As of right now I’m keeping it down to the bare minimum until I can see how it all works. I have this bit of code that will return me an image when I go the correct URL:
class download:
def GET(self, args):
path = 'path/to/image'
web.header('Content-type','images/jpeg')
web.header('Content-transfer-encoding','binary')
return open(path, 'rb').read()
So when I go to the URL it automatically downloads the image however, it names it as ‘download’ and has no extension. Is there a way to specify the file name for when it get’s downloaded? Does this have to be specified in the headers somewhere?
You need set the
Content-Dispositionheader, for example:reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1