Skip to content

cheeyeo/FastAPI_S3_Uploads

Repository files navigation

FastAPI File Uploads

Learning how to use FastAPI for file uploads to S3 which includes a ReactUI that shows realtime updates via websocket from the API

The realtime updates are provided via MongoDB changesets and can run locally in docker containers.

This is still a works in progress. Part of the codebase is generated using Gemini and is currently being refined.

More attempts are underway to use spec driven development.

REF

( upload larget files using boto3 s3 transferconfig )

MONGODB ON DOCKER

docker exec -it fastapi_file_upload-mongo-1 mongosh -u root -p example

On mongodb init scripts not loading to create initial database:

If the /data/db volume already exists the init scripts won't run

Also need to mount the directory the script is in and not the script itself..

MongoDB Change Streams require a replica set. According to MongoDB, a replica set in MongoDB is a group of mongod processes that maintain the same data set, providing redundancy and high availability.

( WORKS BUT ONLY IN SHELL SCRIPT WITHOUT AUTH ) https://www.mongodb.com/resources/products/compatibilities/deploying-a-mongodb-cluster-with-docker

( THIS IS THE ONLY ONE THAT WORKS )

NEED TO UPDATE THE /etc/hosts file else the client code won't work.... https://medium.com/@ravikushwaha18.rk/setting-up-a-mongodb-replica-set-with-docker-compose-62ece5c295a1

https://anthonysimmon.com/the-only-local-mongodb-replica-set-with-docker-compose-guide-youll-ever-need/

Generate large file for testing uploads

use dd on ubuntu

#kilobytes
dd if=/dev/zero of=filename bs=1 count=0 seek=200K

#megabytes
dd if=/dev/zero of=filename bs=1 count=0 seek=200M

#gigabytes
dd if=/dev/zero of=filename bs=1 count=0 seek=200G

#terabytes
dd if=/dev/zero of=filename bs=1 count=0 seek=200T

ASYNC

https://betterstack.com/community/guides/scaling-python/error-handling-fastapi/#creating-custom-exceptions-in-fastapi

S3 PRESIGNED URL UPLOAD

https://docs.aws.amazon.com/AmazonS3/latest/userguide/PresignedUrlUploadObject.html

About

Learning how to do file uploads in FastAPI to S3

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors