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
  • Create a bucket
  • Upload a file
  • Requesting IPFS CID and Arweave Hash
  1. Storage
  2. Bucket
  3. Bucket API - S3 Compatible
  4. Coding Examples

AWS SDK - Java

Last updated 1 year ago

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

Preparation

  • In your development environment, Java.

  • the AWS SDK for Java.

  • 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

Create a bucket

bucketName: The desired bucket name to create

accessKey: Bucket-Access Keys-API key

secretKey: Bucket-Access Keys-API Secret

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

region: Default filled in with "4everland"

import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.CreateBucketRequest;
import com.amazonaws.services.s3.model.GetBucketLocationRequest;

import java.io.IOException;

public class CreateBucket2 {

    public static void main(String[] args) throws IOException {
        String bucketName = "new-bucketname";
        String accessKey = "4EVERLAND-Bucket-APIKey";
        String secretKey = "4EVERLAND-Bucket-APISecret";
        String endpoint_url = "https://endpoint.4everland.co";
        String region = "4everland";
        try {
            AmazonS3ClientBuilder.standard();
            AWSCredentials credentials = new BasicAWSCredentials(accessKey,secretKey);
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .withCredentials(credentials)
                    .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint_url, region))
                    .build();

            if (!s3Client.doesBucketExistV2(bucketName)) {
                s3Client.createBucket(new CreateBucketRequest(bucketName));

                String bucketLocation = s3Client.getBucketLocation(new GetBucketLocationRequest(bucketName));
                System.out.println("Bucket location: " + bucketLocation);
            }
        } catch (AmazonServiceException e) {
            e.printStackTrace();
        } catch (SdkClientException e) {
            e.printStackTrace();
        }
    }
}

Upload a file

bucketName: Your bucket name

stringObjKeyName: The name of the file to be uploaded

fileObjKeyName: The name of the file to be uploaded

fileName: The path of the file to be uploaded

accessKey: Bucket-Access Keys-API key

secretKey: Bucket-Access Keys-API Secret

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

region: Default filled in with "4everland"

import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PutObjectRequest;

import java.io.File;
import java.io.IOException;

public class UploadObject {

    public static void main(String[] args) throws IOException {
        String bucketName = "4everland-bucketname";
        String stringObjKeyName = "object-name";
        String fileObjKeyName = "object-name";
        String fileName = "/path/to/4everland/4ever.png";
        String accessKey = "4EVERLAND-Bucket-APIKey";
        String secretKey = "4EVERLAND-Bucket-APISecret";
        String endpoint_url = "https://endpoint.4everland.co";
        String region = "4everland";

        try {
            AWSCredentials credentials = new BasicAWSCredentials(accessKey,secretKey);
            AmazonS3 s3Client = AmazonS3ClientBuilder.standard()
                    .withCredentials(credentials)
                    .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint_url, region))
                    .build();

            s3Client.putObject(bucketName, stringObjKeyName, "Uploaded String Object");

            PutObjectRequest request = new PutObjectRequest(bucketName, fileObjKeyName, new File(fileName));
            ObjectMetadata metadata = new ObjectMetadata();
            metadata.setContentType("plain/text");
            metadata.addUserMetadata("title", "someTitle");
            request.setMetadata(metadata);
            s3Client.putObject(request);
        } catch (AmazonServiceException e) {

            e.printStackTrace();
        } catch (SdkClientException e) {
            e.printStackTrace();
        }
    }
}

Requesting IPFS CID and Arweave Hash

bucket: The bucket name where the target file is stored

key: The name of the target file

HeadObjectRequest headObjectRequest = HeadObjectRequest.builder()
  .bucket("4everland-bucketname")
  .key("your-object-name")
  .build();
  
HeadObjectResponse headObjectResponse = s3Client.headObject(headObjectRequest);
System.out.println("ipfs hash: " + headObjectResponse.metadata().get("ipfs-hash");
//If it is an Arweave type of bucket.
System.out.println("arweave hash: " + headObjectResponse.metadata().get("arweave-hash");

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

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