I want users to be able to download file from my django web app. I wrote the below codes, but when I download a file, the file will turn into an error file. It won't open and the total size of the file would be 0 bytes.
Models:
class Emov(models.Model):
User=models.ForeignKey(User)
mov_file=models.FileField(upload_to='miiv')
mov_name=models.CharField(max_length=50)
email=models.EmailField() #email of the uploader
download_count=models.PositiveIntegerField(default=0)
#other fields follows
@property
def pretty_name(self):
return "{0}.{1}".format(slugify(self.title),
os.path.splitext(
self.mov_name.name)[1])
Views:
def document_view(request,emov_id):
fileload=Emovl.objects.get(id=emov_id)
response=HttpResponse()
response["Content-Disposition"]= "attachment; filename={0}".format(
fileload.pretty_name)
response['X-Accel-Redirect']="/protected/{0}".format(
fileload.mov_name.name)
return response
Nginx
location /protected/ {
internal;
root /C:/Python27/Scripts/env/Scripts/digi/media/miiv/;
}
What am I missing?