2016-03-03 108 views
1

我試圖通過一個url下載文件。它通常是下載的,但問題是,當我試圖打開文件時,它有0個字節。通過url下載文件python

有沒有人遇到過這個問題,或者有從哪裏來的想法?

這是我的代碼

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 
+0

請指出您正在使用的Web框架? – Selcuk

+0

您是否嘗試將'content_type'設置爲'application/binary'? – Himanshu

+0

@Selcuk框架是Django – gegham

回答

1

Nginx的不支持頭。您必須改爲使用X-Accel-Redirect

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