summaryrefslogtreecommitdiff
path: root/addons/web/controllers
diff options
context:
space:
mode:
authorEL HADJI DEM <elhadji.dem@savoirfairelinux.com>2014-07-16 17:14:12 -0400
committerMartin Trigaux <mat@odoo.com>2014-12-22 14:47:18 +0100
commitae056ddc07d57fec1706cd960da7ff7ca27a7769 (patch)
tree2b4cf0523928662af37ba22ca99e1468c28a1e07 /addons/web/controllers
parente947611b51d0eee42c53c1c8f1c2cf480ae6c89f (diff)
[IMP] web: better content-type for attachments
Add the corresponding content type document instead the default content type. This allows browser to detect the type of file being downloaded. Fixes #1225
Diffstat (limited to 'addons/web/controllers')
-rw-r--r--addons/web/controllers/main.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py
index 4a9af66b641..7890d0947b0 100644
--- a/addons/web/controllers/main.py
+++ b/addons/web/controllers/main.py
@@ -1101,10 +1101,14 @@ class Binary(http.Controller):
Model = request.registry[model]
cr, uid, context = request.cr, request.uid, request.context
fields = [field]
+ content_type = 'application/octet-stream'
if filename_field:
fields.append(filename_field)
if id:
+ fields.append('file_type')
res = Model.read(cr, uid, [int(id)], fields, context)[0]
+ if res.get('file_type'):
+ content_type = res['file_type']
else:
res = Model.default_get(cr, uid, fields, context)
filecontent = base64.b64decode(res.get(field, ''))
@@ -1115,7 +1119,7 @@ class Binary(http.Controller):
if filename_field:
filename = res.get(filename_field, '') or filename
return request.make_response(filecontent,
- [('Content-Type', 'application/octet-stream'),
+ [('Content-Type', content_type),
('Content-Disposition', content_disposition(filename))])
@http.route('/web/binary/saveas_ajax', type='http', auth="public")
@@ -1128,6 +1132,7 @@ class Binary(http.Controller):
id = jdata.get('id', None)
filename_field = jdata.get('filename_field', None)
context = jdata.get('context', {})
+ content_type = 'application/octet-stream'
Model = request.session.model(model)
fields = [field]
@@ -1136,7 +1141,10 @@ class Binary(http.Controller):
if data:
res = { field: data }
elif id:
+ fields.append('file_type')
res = Model.read([int(id)], fields, context)[0]
+ if res.get('file_type'):
+ content_type = res['file_type']
else:
res = Model.default_get(fields, context)
filecontent = base64.b64decode(res.get(field, ''))
@@ -1148,7 +1156,7 @@ class Binary(http.Controller):
if filename_field:
filename = res.get(filename_field, '') or filename
return request.make_response(filecontent,
- headers=[('Content-Type', 'application/octet-stream'),
+ headers=[('Content-Type', content_type),
('Content-Disposition', content_disposition(filename))],
cookies={'fileToken': token})