From the course: Advanced Python Projects: Build AI Applications
Unlock the full course today
Join today to access over 24,200 courses taught by industry experts.
Upload files to Amazon S3 storage bucket - Python Tutorial
From the course: Advanced Python Projects: Build AI Applications
Upload files to Amazon S3 storage bucket
- [Instructor] Next we're going to learn how to upload a file to Amazon S3 storage. So we're going to have the /uploadFile FastAPI endpoint asynchronously process the file uploads. We're going to have it temporarily saved the file locally, upload it to Amazon S3, remove it from the local file system, and return a JSON response containing the file name and S3 file path, with the appropriate exception handling at the end. Let's check out how to do that. So over here in this section, we defined a FastAPI endpoint at /uploadFile that handles the HTTP post request. The function upload to S3 is an asynchronous function that takes a file input using the FileUpload type. Then we print the file name extracted from the uploaded file path. Next, we're going to be uploading our files to the S3. This code opens the local file for writing in binary mode, reads the content of the uploaded file, asynchronously writes the content to the…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Setting up MongoDB4m 24s
-
(Locked)
Generate chat responses using GPT-3.5 and Langchain2m 46s
-
(Locked)
Load conversation history for a given session ID1m 16s
-
(Locked)
Create new sessions and add chat history to existing sessions1m 11s
-
(Locked)
Setup FastAPI app, CORS, S3 session, and obtain a chat response3m 43s
-
(Locked)
Upload files to Amazon S3 storage bucket2m 39s
-
(Locked)
Deploy and run the chatbot4m 2s
-
(Locked)
Challenge: Complete the backend code for file upload2m 13s
-
(Locked)
Solution: Complete the backend code for file upload9m 52s
-
(Locked)
-
-