开发者

Get selected path from response

开发者 https://www.devze.com 2023-01-10 21:32 出处:网络
I am using response.headers[\'Content-Type\'] = gluon.contenttype.contenttype(\'.xls\') response.headers[\'Content-disposition\'] = \'attachment; filename=projects.xls\'

I am using

response.headers['Content-Type'] = gluon.contenttype.contenttype('.xls')
response.headers['Content-disposition'] = 'attachment; filename=projects.xls'

to generate开发者_开发问答 save as dialog box.

Is there a way to get the selected path by the user?


The browser displays the Save As dialog box to the user, then writes your content into that file. It doesn't inform the server what path the content was saved to. I'm afraid you can't get that information.


If your question is about how to send the file contents to the user, you simply write the content to your response object. The browser takes care of actually writing the file to the path selected by the user.

In Django, you would do something like:

def view(request):
    # get the file content from somewhere
    response = HttpResponse(file_content, mimetype='application/vnd.ms-excel')
    response['Content-Disposition'] = 'attachment; filename=projects.xls'
    return response

The browser will then prompt the user for a path and save the file "projects.xls" to that path.

0

精彩评论

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

关注公众号