0

I've recently been deploying a Django project on a digital ocean server (ubuntu). I'm using Nginx and securing the connection with lets encrypt. Here's my problem: I was able to use python magic to validate uploads (during development), but it doesn't seem to be working on on the production server. Here's my form validation:

class PostForm(forms.ModelForm):

    def clean_sound(self):
        file = self.cleaned_data.get('sound',False)
        mime = magic.from_buffer(file.read(), mime=True)
        print(mime)
        if not mime == 'audio/mpeg':
            raise forms.ValidationError('File must be mp3')
        else:
            return file


    class Meta:
        model = Places
        fields = [
        'usersave',
        'title',
        'longitude',
        'latitude',
        'sound',

        ]

So yeah, it works perfectly fine on the development server, but throws the 'File must be mp3' validation error every time on the production server. Even if it is the correct file type. What gives?

Adam Yui
  • 139
  • 11
  • 2
    The first thing that pops out: `if file:` will never be reached. You either `raise` or `return` before. – Klaus D. May 25 '17 at 03:00
  • aha, you're absolutely right. I actually forgot to remove that bit of code that I I was using as a less-safe but working alternative, I'll go ahead and edit it out – Adam Yui May 25 '17 at 03:03
  • 1
    what does `print(mime)` produce? – e4c5 May 25 '17 at 03:28
  • forgive my ignorance, what is the best way to display print(mime) ? I've heard someone mention using Django shell to debug but I've set debug to false in settings – Adam Yui May 25 '17 at 03:33
  • I see after a little looking, this requires a little work after turning off debugging. I'll work on it and see if I can get it to spit out some error – Adam Yui May 25 '17 at 03:38

0 Answers0