Skip to content

An example project on how to implement an s3 storage provider in Node.js

Notifications You must be signed in to change notification settings

Forward-Digital/node-s3-storage-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Forward Digital Logo

S3 Storage with Node.js Example App

This project demonstrates how you can use S3 object storage providers like Vultr, AWS and Digital Ocean in Node.js.

I would recommend reading my blog post explaining how it works first.


Running the app

The app uses dotenv environment variables to store your S3 bucket credentials. You will need to create a .env file in the root of the project.

The .env file should look like the following:

S3_BUCKET_NAME=your_bucket_name // e.g my-bucket
S3_ENDPOINT_URL=your_endpoint_url // e.g https://eu.amazons3.com/
S3_ACCESS_KEY=your_access_key
S3_SECRET_KEY=your_secret_access_key

Once you have created the environment you will be able to install and run the project:

> npm install
> npm start

Using the app

The code for interacting with the S3 object storage is framework agnostic. This code is all held inside the objectStorage directory. However to demonstrate how to use the functions I have used Express and Multer to create a couple of endpoints that will upload and delete a file.

Upload Endpoint

URL: POST http://localhost:3000/upload

Request should be form-data and the file should have the key formFile. A quick HTML form example:

<form action="http://localhost:3000/upload" method="post">
    <input type="file" name="formFile" />
    <input type="submit" value="Submit">
</form>

This will upload the file with the name my-custom-filename.xxx


Delete Endpoint

URL: DELETE http://localhost:3000/delete?filename=xxxx&path=xxxx

Query Parameters:

filename - the name of the file in the bucket. In the example above it will be my-custom-filename.xxx

path - This is optional. If you want to delete a file within a subdirectory, this should be the path to that directory, e.g images/logos

About

An example project on how to implement an s3 storage provider in Node.js

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published