ASW-S3

TypeScript Express Integration with AWS S3 - 18/07/2023

5 min read

Hello World

Tutorial: TypeScript Express Integration with AWS S3

This tutorial will show you how to use the aws-s3-startup project, which is a sample application for uploading, downloading, and deleting files on AWS S3 using Express with TypeScript.

Prerequisites:

Step 1: Configuration

  1. Clone the aws-s3-startup project to your computer:
  2. terminal
    git clone  https://github.com/xDaswx/aws-s3-startup.git
    cd  aws-s3-startup

  3. Install project dependencies:

  4. terminal
      npm install
  5. Create a .env file at the root of the project with your AWS credentials:
  6.     AWS_BUCKET_NAME=your_bucket_name
        AWS_BUCKET_REGION=your_region
        AWS_ACCESS_KEY=your_access_key
        AWS_SECRET_KEY=your_secret_key
            

Step 2: Running the Server

  1. Start the server using the command:

  2. terminal
    npm run  dev:server

  3. This will start the Express server locally on port 3333.

Step 3: Testing the Functionalities

Now that the server is running, you can test the functionalities of uploading, downloading, and deleting files on AWS S3.

File Upload

Make a POST request to the route / by sending a file in the request body with the key "image". For example, using curl:

curl   -X POST -F "image=@path/to/your/file.jpg" http://localhost:3333

The response will be a JSON with the URL of the file on S3, indicating that the upload was successful.

File Download

Make a GET request to the route /get/:filename, replacing :filename with the name of the file you want to download. For example:

curl   http://localhost:3333/get/your-file.jpg -o downloaded-file.jpg

The file will be downloaded to your local directory with the name "downloaded-file.jpg".

File Deletion

Make a DELETE request to the route /:filename, replacing :filename with the name of the file you want to delete. For example:

curl   -X DELETE http://localhost:3333/your-file.jpg

The response will be a JSON indicating that the file was deleted.

Conclusion

Congratulations! You have completed the TypeScript Express integration with AWS S3 tutorial. Now you have a functional application to perform file upload, download, and deletion on AWS S3 using Express and TypeScript.

Remember to adapt the tutorial and routes according to your project's needs, and make sure to follow security best practices when dealing with credentials and sensitive information.

I hope this tutorial has been helpful! If you have any questions or need further assistance, feel free to ask. Happy coding!

Repository: aws-s3-startup