Python Django Tutorial: Full-Featured Web App Part 13 - Using AWS S3 for File Uploads

Corey Schafer · 164K views · 2019 · 26:35

Open on YouTube

Web developmentCloud, DevOps & reliabilityPython, Ruby & scripting languagestutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it as the step-by-step reference for wiring AWS S3 into a Django app for file uploads, and then cite it when their own setup hits 403 or CORS problems.

Recommended by 1 people across 1 different months, 2019 to 2020.

What it is

Part 13 of Corey Schafer's Django web app series, showing how to set up an AWS S3 bucket, an IAM user and django-storages so media uploads are served from S3 instead of the local filesystem. It covers the S3 CORS config and environment variables for the credentials.

What people said

Recommends aj3409 · 2020-05 · Stack Overflow · on “How to store an uploaded file in Heroku using Flask in Python?”

Heroku has a ephemeral filesystem -- meaning that the file is only saved in Heroku while the dyno is running and is deleted afterwards. The option I would use is AWS S3, where I have stored images on there. Here's a good link to get you started with AWS S3 and how to set it up and use it: [this video] After you have set up your AWS S3 bucket: import boto3 BUCKET = 'my-bucket-name' s3 = boto3.client("s3", aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID'), aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY')) bucket_resource = s3 bucket_resource.upload_file(Bucket = BUCKET, Filename=picture_fn, Key=picture_fn) # uploading # retrieving image_file = s3.generate_presigned_url('get_object'

Cites Prateek Gautam · 2019-08 · Stack Overflow · on “Unable to get Images from AWS-S3 bucket in django-app?”

I'm using AWS-S3 to store my users' profile images. I've repeated this process 7-8 times but when I open my app on local machine(I've not deployed it yet) the user profile images aren't there and it shows the alt='not found' in place of images. I've made a user in IAM and a bucket in S3 same as in this [this video] tutorial nearly 5 times but there's no way I'm getting the images. Also when I right click on any image in my app and go into the image location I'm getting this in my browser. This XML file does not appear to have any style information associated with it. The document tree is shown below. AccessDenied Access Denied6683BC64F8FCAB0CE2foYctY9f7GMW+VI64vr3rRfMPrXXGfscryk3Eqo7meEtenXCLSa4k

Cites palebluedot · 2020-09 · Stack Overflow · on “Troubling accessing media on AWS S3, ERROR 403, on Django app”

I am having trouble accessing media files uploaded on AWS S3 for my Django app. I was attempting to use Boto3 and Django-Storages libraries and followed these tutorials: [LINK] [this video] Both the Django Admin website and my front-end website are not able to load any of the static and media content. The Django admin is rendered without any CSS, and similarly my front-end has no images. [LINK] [LINK] AWS Configurations were added to the settings.py file: AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID') AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY') AWS_S3_REGION_NAME = "me-south-1" AWS_STORAGE_BUCKET_NAME = 'jooler-mea' AWS_S3_CUSTOM_DOMAIN = '%s.s3.me-south-1.amazonaws.com' % AWS_STORAG

Cites nandesuka · 2020-12 · Stack Overflow · on “S3 buckets CORS policy Django”

I'm trying to set up an s3 bucket so my Django app can upload and grab user media files. I've come to the part in this video [this video] where you set the cors policy. In this tutorial he uses XML but aws now wants json. I don't know what to put. I want my website to be able to GET, PUT, POST, PATCH and DELETE. My app is a Django app hosted on a Digital Ocean droplet Edit: I've found an example which I've edited and added to my config [ { "AllowedHeaders": [ "*" ], "AllowedMethods": [ "PUT", "POST", "DELETE" ], "AllowedOrigins": [ " [LINK] " ], "ExposeHeaders": [] }, { "AllowedHeaders": [ "*" ], "AllowedMethods": [ "PUT", "POST", "DELETE" ], "AllowedOrigins": [ " [LINK] " ], "ExposeHeaders": []