Sorry for my delay in answer. I've taken back the project.
The solution of Leonel works well if I want to show an pdf from another
website, but when I try to download a file loaded in my own web site
(Web2py's upload/download method) I get the message that the file is not
found.
I show you the table definition:
db.define_table('enlacesweb_documentos',
Field('categoria', db.categorias_documentos),
Field('nombre'),
Field('documento', 'upload',
uploadfolder=os.path.join(request.folder,'uploads/docs_y_normatividad')),
Field('fecha', 'date'),
Field('descripcion_documento', 'text'),
Field('muestra_en_portada','boolean'),
Field('imagen_portada', 'upload',
uploadfolder=os.path.join(request.folder,'uploads/docs_y_normatividad')),
Field('texto_imagen_portada', label="Texto de la imagen en
portada"),
format='%(categoria)s')
As you see I'm using an subfolder inside uploads folder.
The download function, serving swf, pdf and another type of files:
def download():
"""
allows downloading of uploaded files
http://..../[app]/default/download/[filename]
"""
import os
if (request.args(0) or '').endswith('swf'):
response.headers['Content-Disposition'] = ''
filename = os.path.join(request.folder, 'uploads', request.args(0))
return response.stream(open(filename,'rb'))
elif (request.args(0) or '').endswith('pdf'):
filename=os.path.join(request.folder, 'uploads', request.args(0))
response.headers['ContentType'] ="application/pdf"
response.headers['Content-Disposition']="inline; filename.pdf" +
filename
return response.stream(open(filename), chunk_size=65536)
else:
return response.download(request,db)
The elif section works well with external pdf to show, but for those
uploaded with Web2py's upload method I get the error the pdf is not found,
if I omit the elif and use the else I can to download the pdf file, but I
want the web browser open it.
I hope you can understand me.
How to fix this?
Thanks in advanced.
--
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].
For more options, visit https://groups.google.com/d/optout.