it's work with web2py
inline for pdf, jpeg, png ...
save file fot other file types
def doc2user():
# read from db.table orig file name and path to file in upfolder
import os
prn_id = request.args(0,cast=int)
task = db.zurina(prn_id) or error()
qu=db.zurina.id == prn_id
res= db(qu).select().first()
upfolder= os.path.join(request.folder, 'docfiles')
# path to file content
file_path = os.path.join( upfolder, res.new_image_file)
# orig file name
ext = os.path.splitext( res.jenka_fnm )
with open(file_path, 'rb') as f:
file_text= f.read()
from gluon.contenttype import contenttype
tru_ext=''
if len(ext) and len(ext[1]):
tru_ext = ext[1].lower()
if len(tru_ext) :
response.headers['Content-Type'] = contenttype(tru_ext)
else:
response.headers['Content-Type'] =
contenttype('application/octet-stream')
if len(tru_ext) and tru_ext.endswith(('pdf','jpeg', 'jpg', 'png',
'bmp')):
response.headers['Content-disposition'] = 'inline;
filename=\"%s"' % ( res.jenka_fnm)
else:
response.headers['Content-disposition'] = 'attachment;
filename=\"%s"' % ( res.jenka_fnm)
# some debug string, you can view it in browser
#return "{}".format( file_path )
return file_text
Also, we need the quotes 'attachment; filename=\"%s"' % ( res.jenka_fnm)
^^^^^^^
четверг, 24 сентября 2020 г., 17:54:53 UTC+3 пользователь
[email protected] написал:
>
> Hi,
> i have a controller with this :
> response.headers['Content-Disposition'] = 'inline; filename=%s' %
> request.vars.filename
>
> to force streaming the pdf file , and i do not why it does not work ..
> any idea ?
>
> Thank you
>
>
>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/web2py/7db8b3d8-b6e0-4759-ab52-6491b229e0b6o%40googlegroups.com.