Created
December 23, 2013 12:41
-
-
Save goromlagche/8096470 to your computer and use it in GitHub Desktop.
django file download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def send_file(request,file_name): | |
file_path = settings.MEDIA_ROOT +'/'+ file_name | |
file_wrapper = FileWrapper(file(file_path,'r')) | |
file_mimetype = mimetypes.guess_type(file_path) | |
response = HttpResponse(file_wrapper, content_type=file_mimetype ) | |
file_name = file_name.split("/") | |
filename = file_name[4] | |
response['X-Sendfile'] = file_path | |
response['Content-Length'] = os.stat(file_path).st_size | |
response['Content-Disposition'] = 'attachment; filename='+filename | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment