mirror of
https://github.com/moparisthebest/HttpUploadComponent
synced 2024-11-21 16:35:04 -05:00
Merge pull request #15 from SamWhited/mime_types
Set content-type header based on mime-type
This commit is contained in:
commit
bd4e1e4c5a
@ -146,7 +146,10 @@ class HttpHandler(BaseHTTPRequestHandler):
|
|||||||
try:
|
try:
|
||||||
with open(filename,'rb') as f:
|
with open(filename,'rb') as f:
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header("Content-Type", 'application/octet-stream')
|
mime, _ = mimetypes.guess_type(filename)
|
||||||
|
if mime is None:
|
||||||
|
mime = 'application/octet-stream'
|
||||||
|
self.send_header("Content-Type", mime)
|
||||||
self.send_header("Content-Disposition", 'attachment; filename="{}"'.format(os.path.basename(filename)))
|
self.send_header("Content-Disposition", 'attachment; filename="{}"'.format(os.path.basename(filename)))
|
||||||
fs = os.fstat(f.fileno())
|
fs = os.fstat(f.fileno())
|
||||||
self.send_header("Content-Length", str(fs.st_size))
|
self.send_header("Content-Length", str(fs.st_size))
|
||||||
|
Loading…
Reference in New Issue
Block a user