[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
This commit is contained in:
parent
11cd22711c
commit
7b0d707417
|
@ -1086,10 +1086,14 @@ class Binary(http.Controller):
|
||||||
Model = request.registry[model]
|
Model = request.registry[model]
|
||||||
cr, uid, context = request.cr, request.uid, request.context
|
cr, uid, context = request.cr, request.uid, request.context
|
||||||
fields = [field]
|
fields = [field]
|
||||||
|
content_type = 'application/octet-stream'
|
||||||
if filename_field:
|
if filename_field:
|
||||||
fields.append(filename_field)
|
fields.append(filename_field)
|
||||||
if id:
|
if id:
|
||||||
|
fields.append('file_type')
|
||||||
res = Model.read(cr, uid, [int(id)], fields, context)[0]
|
res = Model.read(cr, uid, [int(id)], fields, context)[0]
|
||||||
|
if res.get('file_type'):
|
||||||
|
content_type = res['file_type']
|
||||||
else:
|
else:
|
||||||
res = Model.default_get(cr, uid, fields, context)
|
res = Model.default_get(cr, uid, fields, context)
|
||||||
filecontent = base64.b64decode(res.get(field) or '')
|
filecontent = base64.b64decode(res.get(field) or '')
|
||||||
|
@ -1100,7 +1104,7 @@ class Binary(http.Controller):
|
||||||
if filename_field:
|
if filename_field:
|
||||||
filename = res.get(filename_field, '') or filename
|
filename = res.get(filename_field, '') or filename
|
||||||
return request.make_response(filecontent,
|
return request.make_response(filecontent,
|
||||||
[('Content-Type', 'application/octet-stream'),
|
[('Content-Type', content_type),
|
||||||
('Content-Disposition', content_disposition(filename))])
|
('Content-Disposition', content_disposition(filename))])
|
||||||
|
|
||||||
@http.route('/web/binary/saveas_ajax', type='http', auth="public")
|
@http.route('/web/binary/saveas_ajax', type='http', auth="public")
|
||||||
|
@ -1113,6 +1117,7 @@ class Binary(http.Controller):
|
||||||
id = jdata.get('id', None)
|
id = jdata.get('id', None)
|
||||||
filename_field = jdata.get('filename_field', None)
|
filename_field = jdata.get('filename_field', None)
|
||||||
context = jdata.get('context', {})
|
context = jdata.get('context', {})
|
||||||
|
content_type = 'application/octet-stream'
|
||||||
|
|
||||||
Model = request.session.model(model)
|
Model = request.session.model(model)
|
||||||
fields = [field]
|
fields = [field]
|
||||||
|
@ -1121,7 +1126,10 @@ class Binary(http.Controller):
|
||||||
if data:
|
if data:
|
||||||
res = {field: data, filename_field: jdata.get('filename', None)}
|
res = {field: data, filename_field: jdata.get('filename', None)}
|
||||||
elif id:
|
elif id:
|
||||||
|
fields.append('file_type')
|
||||||
res = Model.read([int(id)], fields, context)[0]
|
res = Model.read([int(id)], fields, context)[0]
|
||||||
|
if res.get('file_type'):
|
||||||
|
content_type = res['file_type']
|
||||||
else:
|
else:
|
||||||
res = Model.default_get(fields, context)
|
res = Model.default_get(fields, context)
|
||||||
filecontent = base64.b64decode(res.get(field) or '')
|
filecontent = base64.b64decode(res.get(field) or '')
|
||||||
|
@ -1133,7 +1141,7 @@ class Binary(http.Controller):
|
||||||
if filename_field:
|
if filename_field:
|
||||||
filename = res.get(filename_field, '') or filename
|
filename = res.get(filename_field, '') or filename
|
||||||
return request.make_response(filecontent,
|
return request.make_response(filecontent,
|
||||||
headers=[('Content-Type', 'application/octet-stream'),
|
headers=[('Content-Type', content_type),
|
||||||
('Content-Disposition', content_disposition(filename))],
|
('Content-Disposition', content_disposition(filename))],
|
||||||
cookies={'fileToken': token})
|
cookies={'fileToken': token})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue