AWS SDK - JavaScript
Learn how to use the AWS SDK for JavaScript with Filebase.
What is AWS SDK - JavaScript?
AWS SDKs (software development kits) help simplify coding and application development by supporting and providing code objects for use with S3-compatible services. There are a variety of different AWS SDKs, each for a different coding language. This guide covers AWS SDK - JavaScript.
The AWS SDK for JavaScript supports three runtimes:
JavaScript
Node.js
React Native for mobile development
AWS SDK - JavaScript also supports cross-runtime. Cross-runtime is a service client package that can be run on browsers, Node.js, and React-Native without needing any change to the code.
This guide was written using Ubuntu 20.04 and tested using the command line interface. If you are using an Integrated Development Environment (IDE), the installation of dependencies and modules will vary.
Declare the S3 Client
The following code example defines the S3 client, and does not return any output. Replace the following values in the code to match your configuration:
accessKeyId: Your Filebase Access Key
secretAccessKey: Your Filebase Secret Key
Retrieving Buckets
The following code example returns a list of buckets under your Filebase account. Replace the following values in the code to match your configuration:
accessKeyId: Your Filebase Access Key
secretAccessKey: Your Filebase Secret Key
Creating a Bucket
The following code example creates a new Filebase bucket. Replace the following values in the code to match your configuration:
accessKeyId: Your Filebase Access Key
secretAccessKey: Your Filebase Secret Key
Bucket: Your Filebase Bucket Name To Be Created
Bucket names must be unique across all Filebase users, be between 3 and 63 characters long, and can contain only lowercase characters, numbers, and dashes.
Buckets created through this method will be automatically created on the IPFS network.
Listing Files in a Bucket
The following code example returns a list of objects in the bucket name provided. Replace the following values in the code to match your configuration:
accessKeyId: Your Filebase Access Key
secretAccessKey: Your Filebase Secret Key
Bucket: Your Filebase Bucket Name
Uploading Objects
The following code example uploads an object to the bucket name provided. Replace the following values in the code to match your configuration:
accessKeyId: Your Filebase Access Key
secretAccessKey: Your Filebase Secret Key
Bucket: Your Filebase Bucket Name
Key: The Local Path To The Object To Be Uploaded
Content Type: The Type of Object Being Uploaded
For more information on the AWS SDK for JavaScript, check out the documentation here.
Last updated