简体   繁体   中英

download file via url python

I'm trying to download a file via an url. It is normally downloaded, but the problem is that , when I'm trying to open the file, it has 0 bytes.

Does anyone met this problem, or have idea from where can it come?

This is my code

def download():
    file_name = "/opt/static/avatar/20/mouse.png"
    response = HttpResponse(content_type='application/force-download')
    response['Content-Disposition'] = 'attachment; filename=%s' % smart_str(file_name)
    response['X-Sendfile'] = smart_str(path)
    return response 

NginX does not support X-Sendfile header. You must use X-Accel-Redirect instead:

response['X-Accel-Redirect'] = smart_str(path)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM