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?
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/b47b6cb3-f3d5-4ffd-b02e-45dd008fb92e%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.