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

preview_player
Показать описание
In this Python Django Tutorial, we will be learning how to set up AWS S3 so that we can host our media files from that service instead of our local filesystem. AWS S3 is very affordable and will also allow our application to scale much more than if our files lived on our local filesystem. Let's get started...

The code for this series can be found at:

Environment Variables (Windows):

Environment Variables (Mac and Linux):

✅ Support My Channel Through Patreon:

✅ Become a Channel Member:

✅ One-Time Contribution Through PayPal:

✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey's Public Amazon Wishlist

✅ Equipment I Use and Books I Recommend:

▶️ You Can Find Me On:

#Python #Django
Рекомендации по теме
Комментарии
Автор

In the New AWS Interface the CORS config is in JSON format, use an online converter to convert XML to JSON.

Praful
Автор

Still usefull in 2021 but keep in mind the following:
1) You also need to add this in "settings.py":
AWS_S3_REGION_NAME = 'us-east-2' # Your region name
AWS_S3_SIGNATURE_VERSION = 's3v4'

2) The CORS config is now json format:
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"POST",
"PUT"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]

computinghub
Автор

You are the most underrated hero in this galaxy, thank you so much buddy . You are doing a noble cause <3<3<3

manukyanq
Автор

I would like to see the lambda function and maybe show us how to remove the old image from the bucket after the user adds a new one. Btw, your videos are great! Thank you, Corey!

mihainegrisan
Автор

The AWS Lambda tutorial would be great.

BGivo
Автор

this series is an incredible platform for all developers looking to get a detailed, in depth look at building a fully functioning django app, start to finish. Thank you so much for your effort and if I could add, I would love to see a future video that added the ability for users to comment on other users posts (as well as more user to user interactions)!

andrewdenike
Автор

I got an entry level job. I'm learning Terraform to provision AWS resources. I am very new to all of this and this video is just a perfect learning resource. You're the best Corey

MistaT
Автор

New AWS Interface the CORS config is in JSON format:

[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"HEAD",
"DELETE"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [],
"MaxAgeSeconds": 3000
}
]

hope this helps

anishashruti
Автор

thanks for such a great tutorial!

If anyone get an error "required parameter name not set", just restart your console and vscode, and try again.

jn
Автор

In case somebody struggles to get the images loaded, it may turn out that the region name and the signature are not set properly. Make sure to add these variables into your settings.py file:
AWS_S3_SIGNATURE_VERSION = 's3v4'
AWS_S3_REGION_NAME = 'us-east-2' # This one may vary, in case is the wrong one the error message will tell you which region to set to, so no worries

martinnieva
Автор

For people facing AWS4-HMAC-SHA256 error in django-storages (images not loading). Try using this values in settings.py:

if using boto3
AWS_S3_REGION_NAME = 'us-east-2' #change to your region
AWS_S3_SIGNATURE_VERSION = 's3v4'

if using boto
AWS_S3_HOST = 'us-east-2' #change to your region
S3_USE_SIGV4 = True


Btw Corey, you are a True HERO!!. doing such an amazing job

mountaindiaryfilms
Автор

One thing I did not understand was why the MEDIA_ROOT did not have to be changed. It is still set to MEDIA_ROOT = os.path.join(BASE_DIR, 'media') and not to AWS...

It is now redundant to say how good these tutorials are. I basically opened a patreon account just to pay my (very humble) tribute to this guy.

neddolphin
Автор

Nice tutorial! I would also like to see the lambda function (:

MaltheHave
Автор

I would like to say thank you for sharing these awesome python tutorials with every specific detail. I watched this Django series over and over again, which I had never expected. I finished my own django project by following these instructions. I had confuses and problems luckily your videos can always lead me into the right direction. Thanks!

shiqiongxue
Автор

At 25:03 you can see Corey uploaded the file on February 16, 2019, 4:56 PM and here I am following along this tutorial, uploading my image February 16, 2021, 3:23 PM, almost exactly 2 years later! (BTW, the django series is awesome)

zestful
Автор

Thank you very much for this series Corey. I've been meaning to finish your Django series for months and I'm glad I finally have. I've learned a lot because of how well you explain, and break down instructions and programming principles.

czagazeta
Автор

FYI, region is important for django storages s3. Make sure to choose a region that supports v2 authentication. v4 support is allegedly in django storages but doesn't work out of the box by default.

RebeccaBrunner
Автор

As always, you deliver great tutorials ! Please do also tutorial on how to resize the image file inside S3 bucket using the lambda. And how to delete existing image file when user updates his image file to prevent file size getting bigger. Please do both inside S3 and also in local storage.
Thank you so much !

monagulapa
Автор

Alright mates, you don't have to switch to NA servers, all you needed to do is to add region name. AWS_S3_REGION_NAME = 'eu-central-1' fixed everything for me. Add your region name and you good.

Gigolas
Автор

AWS Changed CORS Format! I have a working solution below:

AWS no longer accepts xml for CORS configuration, it must be a JSON.

You will get this error if you use Corys XML:
Expected to be an Array

This solution worked for me:

[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"PUT",
"POST",
"GET"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]

johnstewart