开发者

How can I control the filename of an image in web2py?

I have u开发者_JAVA百科sed the following line

image=URL(r=request,f='nonhomog_plot') to make the image in web2py. The filename of the image will be "nonhomog_plot.png". How can I control the filename of the image? I want the filename to contain an user input variable + "_Figure1.png".


Please ask these questions on the web2py mailing list. That is were the experts are. Here you tend to get generic answers by people who may not be web2py experts. Anyway.

image=URL(r=request,f='nonhomog_plot')

can be rewritten as

image=URL('nonhomog_plot.png')

where I assume nonhomog_plot is a web2py action that streams the file. something like

def nonhomog_plot():
    return response.stream(open('filename.png','rb'))

Now you can add

def nonhomog_plot():
    filename='Figure1.png'
    response.headers['Content-Disposition']='attachment; filename='+filename 
    return response.stream(open('filename.png','rb'))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜