How do i get mu download function to download my image with its original name

33 views
Skip to first unread message

mostwanted

unread,
Apr 18, 2020, 11:57:59 AM4/18/20
to web2py-users
I want to download an image but i want it to download with its originally saved name, is there a way I can modify my download function to do this? So far its downloading properly as desired its just that its renaming images with dates e.g: (IMG-20200418-WA0002)

IMAGE BEING DOWNLOADED

       
{{for details in details:}}
       
<div class="photos">
   
<img id="item" src="{{=URL('download',args=details.image)}}" height="250px" width="250px"/>
   
<span class="details">
   
<span>{{=details.name}}</span> <a href="{{=URL('download', args=details.image)}}">Download Image</a><br />
   
{{=details.place}}
           
</span>
    {{pass}}
    </
div>

DOWNLOAD FUNCTION
def download():
   
return response.download(request, db)

Regards;

Mostwanted

Dave S

unread,
Apr 24, 2020, 2:59:05 AM4/24/20
to web2py-users


On Saturday, April 18, 2020 at 8:57:59 AM UTC-7, mostwanted wrote:
I want to download an image but i want it to download with its originally saved name, is there a way I can modify my download function to do this? So far its downloading properly as desired its just that its renaming images with dates e.g: (IMG-20200418-WA0002)



I believe what you want to do is to set the headers, something like:

response.headers['Content-Disposition']='attachment;filename=graph.%s'%request.args(0)


A quick search of the book didn't turn that up, so I must have gotten it from postings in the forum.   The closest my quick search turned up was Content-Type in <URL:http://web2py.com/books/default/chapter/29/10/services?search=header>, beginning with generic.xml.

/dps

mostwanted

unread,
Jun 3, 2020, 12:23:06 PM6/3/20
to web2py-users
Thank you Dave, I'm just seeing you reply today but totally appreciated.
Reply all
Reply to author
Forward
0 new messages