'AWS image upload with Python/Django is not working

I am a beginner using Python/Django. few months ago I deployed an app that has an image upload feature which is connected with AWS S3 buckets. when I run the server locally on my machine, the app works fine. However I deployed the app to Heroku and the image upload stopped working, no errors in the console, and the image itself is not even uploaded to the AWS bucket.

This is my views for uploading the images:

def add_photo(request, team_id):
    photo_file = request.FILES.get('photo-file', None)
    if photo_file:
        s3 = boto3.client('s3')
        key = uuid.uuid4().hex[:6] + photo_file.name[photo_file.name.rfind('.'):]

        try:
            s3.upload_fileobj(photo_file, BUCKET, key)
            url = f"{S3_BASE_URL}{BUCKET}/{key}"
            photo = Photo(url=url, team_id = team_id)
            photo.save()

        except Exception as e :
            print('An error occured uploading files to s3')
            print(e)
    return redirect('teams_detail', team_id = team_id)

this is the template for upload :

 {% for photo in team.photo_set.all %}

        <img src="{{photo.url}}" alt="{{photo.url}}" class="responsive-img card-panel">
        {% empty %}
            <div class="card-panel teal-text center-align">No Photos Uploaded</div>
        {% endfor %}
        <form class="card-panel" action="{% url 'add_photo' team.id %}" method="POST" enctype="multipart/form-data">
            {% csrf_token %}
            <input type="file" name="photo-file">
            <br>
            <br>
            <input type="submit" class="btn" value="Upload Photo">
        </form>

Like I said this is an app that I created a few months ago. so appreciate if you can point out to me what I am getting wrong or if i missed an important detail to be shared as well

Heroku Logs



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source