4EVERLAND Documents
HomeTwitterDiscordBlogs
  • Welcome to 4EVERLAND
  • Get started
    • Our Features
    • Quick Start Guide
      • Registration
      • Login options
        • MetaMask
        • OKX Wallet
        • Binance Web3 Wallet
        • Bitget Wallet
        • Phantom
        • Petra
        • Lilico
      • Usage Introduction
      • Dashboard stats
      • Account
        • Linking Your EVM Wallet to 4EVERLAND Account
        • Balance Alert
    • Billing and Pricing
      • What is LAND?
      • How to Obtain LAND?
      • Pricing Model
      • Q&As
    • Tokenomics
  • HOSITNG
    • What is Hosting?
      • IPFS Hosting
      • Arweave Hosting
        • Auto-Generation of Manifest
      • Internet Computer Hosting
      • Greenfield Hosting
    • Guides
      • Creating a Deployment
        • With Git
        • With IPFS Hash
        • With a Template
      • Site Deployment
      • Domain Management
        • DNS Setup Guide
        • ENS Setup Guide
        • SNS Setup Guide
          • The gateway: 4sol.xyz
        • SPACE ID Setup Guide
      • Project Setting
        • Git
      • Troubleshooting
      • Common Frameworks
    • Hosting Templates Centre
      • Templates Configuration File
    • Quick Addition
      • Implement Github 4EVER Pin
      • Github Deployment Button
    • Hosting API
      • Create Project API
      • Deploy Project API
      • Get Task Info API
      • IPNS Deployment Update API
    • Hosting CLI
  • Storage
    • Bucket
      • IPFS Bucket
        • Get Root CID - Snapshots
      • Arweave Bucket
        • Path Manifests
          • Instructions for Building Manifest
          • Auto-Generation of Manifest
        • Arweave Tags
        • Unleash Arweave
      • Guides
      • Bucket API - S3 Compatible
        • Coding Examples
          • AWS SDK - Go (Golang)
          • AWS SDK - Java
          • AWS SDK - JavaScript
          • AWS SDK - .NET
          • AWS SDK - PHP
          • AWS SDK - Python
          • AWS SDK - Ruby
        • S3 Tags Instructions
      • 4EVER Security Token Service API
      • Bucket Tools
      • Bucket Gateway Optimizer
    • 4EVER Pin
      • Guides
      • Pinning Services API
      • IPFS Migrator
    • Storage SDK
  • Gateways
    • IPFS Gateway
    • IC Gateway
    • Arweave Gateway
    • Dedicated Gateways
      • Gateway Access Controls
      • Video Streaming
      • IPFS Image Optimizer
    • IPNS Manager
      • IPNS Manager API
  • RPC
    • Guides
    • API Keys
    • JSON Web Token (JWT)
    • What's CUs/CUPS
    • WebSockets
    • Archive Node
    • Debug API
    • Chains RPC
      • BSC / opBNB
      • Ethereum
      • Optimism
      • Polygon
      • Taiko
  • AI
    • AI RPC
      • Quick Start
      • Models
      • API Keys
      • Requests & Responses
      • Parameters
    • 4EVER Chat
  • RaaS - Beta
    • What's Rollups?
    • 4EVER Rollup Stack
  • DePIN
    • 4EVER Network
    • Storage Nodes
  • More
    • Use Cases
      • Livepeer
      • Lens Protocol
      • Optopia.ai
      • Linear Finance
      • Snapshot
      • Tape
      • Taiko
      • Hey.xyz
      • SyncSwap
    • Community
    • Tutorials
    • Security
    • 4EVERLAND FAQ
Powered by GitBook
On this page
  • Preparation
  • Development Examples
  • Install the S3 client
  • Create a bucket
  • Upload a file
  • List the files in the bucket
  • Requesting IPFS CID and Arweave Hash
  1. Storage
  2. Bucket
  3. Bucket API - S3 Compatible
  4. Coding Examples

AWS SDK - JavaScript

Last updated 1 year ago

Please read the following to understand how to use the AWS SDK - JavaScript with the 4EVERLAND Bucket. Combine the AWS SDK API for the JavaScript language with the 4EVERLAND Bucket to achieve file uploads to the IPFS or Arweave storage networks.

Preparation

  • the AWS SDK for JavaScript.

  • a free 4EVERLAND account.

  • If you need to use Arweave storage, you need to create an Arweave bucket. Click to.

  • To obtain the corresponding API key in the bucket, click to.

Development Examples

Install the S3 client

The following code example defines an S3 client and does not return any output. Replace the values in the code below to complete your configuration:

endpoint:https://endpoint.4everland.co

accessKey:Bucket-Access Keys-API Key

secretKey:Bucket-Access Keys-API Secret

region: Default filled in with "4everland"

import { S3 } from '@aws-sdk/client-s3';

const s3 = new S3({
  endpoint:"https://endpoint.4everland.co",
  credentials: {
    accessKeyId: "4EVERLAND-Bucket-APIKey",
    secretAccessKey: "4EVERLAND-Bucket-APISecret"
  },
  region: "4EVERLAND",
});

Create a bucket

bucket: The desired bucket name to create

const params = {
    Bucket: "bucketname",
}
s3.createBucket(params,(err, data)=>{
    if(err){
        console.log(err)
    } else {
        console.log('Bucket created', data)
    }
});

Upload a file

bucket: Your bucket name

Key: The file path for the file to be uploaded

ContentType: The type of the file to be uploaded

const params = {
  Bucket: "4everland-bucketname",
  Key: "/path/to/4everland/4ever.png",
  ContentType: "image/png",
  Body: "data content",
}

s3.putObject(params, (err, data)=>{
     if(err){
        console.log(err)
    } else {
        console.log('Upload success', data)
    }
};

List the files in the bucket

Bucket: Your bucket name

Prefix: Files will be listed according to the provided path. When the input is empty, all files in the bucket will be listed

const params = {
  Bucket: "4everland-bucketname",
  Prefix: "/path/to/" 
};
s3.listObjectsV2(params, function (err, data) {
  if (err) {
    console.log("Error when listing objects", err);
  } else {
    console.log("Success when listing objects", data);
  }
});

Requesting IPFS CID and Arweave Hash

Bucket: The bucket name where the target file is stored

Key: The path of the target file

s3.headObject({
    Bucket: "4everlandbucket",
    Key: "/path/to/4everland/4ever.png",
},(err, data)=>{
    if(!err) {
        console.log(data)
        console.log("ipfs cid:", data.Metadata['ipfs-hash'])
        // If it is an Arweave type of bucke
        console.log("arweave hash:", data.Metadata['arweave-hash']) 
    }
})

If you have any questions, please join our , or send us an email at .

Download and install
Register
learn more
learn more
Discord server
contact@4everland.org