User-uploaded images not saving to media folder in production
<p>I'm building a Django website where users can upload an image via a form that distinguishes them on the site. These are saved in the /grad/media/ folder (where grad is the name of the app).</p>

<p>This is the code that accomplishes this:</p>

<pre><code>uni_object = University.objects.get(user=request.user)
logo = uni_object.logo
if request.method == "POST":
    form = UpdateUniversityForm(request.POST, request.FILES)
    if form.is_valid():
        data = form.cleaned_data

        request.user.email = data['email']
        request.user.save()

        uni_object.university_name = data['university_name']
        uni_object.website = data['website']
        if request.FILES and request.FILES['logo'] != '':
            new_logo = data['logo']
            image = Image.open(new_logo)
            image = image.resize((400,400), Image.ANTIALIAS)
            thumb_io = StringIO.StringIO()
            image.save(thumb_io,format='JPEG')
            new_file_name = str(int(time.time()))
            thumb_file = InMemoryUploadedFile(thumb_io, None, '{0}.jpg'.format(new_file_name), 'image/jpeg',
                              thumb_io.len, None)
            uni_object.logo = thumb_file
        uni_object.save()
        updated = True
        logo = uni_object.logo
</code></pre>

<p>Essentially I need to convert it into a 400x400 square, and then save it. This code will work on localhost, and the file will be saved correctly.</p>

<p>However in Heroku with DEBUG=False:</p>

<ul>
<li>The same code will not save the picture in the media folder</li>
<li>Not even by saving a pic manually via the admin panel will the pic end up in media folder</li>
<li>Even if the photo exists in the media folder, it will not be rendered on the site.</li>
<li>The media folder is pushed to Heroku, so all pics that were on local are also present on heroku.</li>
</ul>

<p>It's as though the media folder was totally ignored essentially, despite looking at the heroku logs I get a HTTP 200 when trying to access it:</p>

<pre><code>2016-10-22T15:39:13.652167+00:00 heroku[router]: at=info method=GET path="/media/1477150753.jpg" 
host=www.gradba.se request_id=7e545ef5-92cf-406c-88c8-26d140541884 fwd="31.50.136.136,141.101.98.8" 
dyno=web.1 connect=0ms service=21ms status=200 bytes=6354
</code></pre>

<p>Can someone tell me why this is happening? I think the media_root is set up correctly because it works on dev.</p>

<p>Thanks!</p>