Django Files Not Downloading Properly

10 views
Skip to first unread message

coded kid

unread,
Nov 22, 2013, 5:57:26 PM11/22/13
to django...@googlegroups.com
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?


Reply all
Reply to author
Forward
0 new messages