Reputation: 1268
i am writing this function in views.py file:
def download(request):
file = open("D:\wamp\www\User_App.rar","r")
mimetype = mimetypes.guess_type("D:\wamp\www\User_App.rar")[0]
if not mimetype: mimetype = "application/octet-stream"
response = HttpResponse(file.read(), mimetype=mimetype)
response["Content-Disposition"]= "attachment; filename=%s" % os.path.split("D:\wamp\www\User_App.rar")[1]
return response
to download file but when that downloads and i open this it is damaged. how to solve this problem.
Upvotes: 0
Views: 565
Reputation: 1121844
Open files in binary mode:
file = open(r"D:\wamp\www\User_App.rar", "rb")
as opening files in text mode means line endings are translated to a platform-neutral \n
character.
Upvotes: 3