AWS SDK - Java

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

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"

Requesting IPFS CID and Arweave Hash

bucket: The bucket name where the target file is stored

key: The name of the target file

If you have any questions, please join our Discord server, or send us an email at [email protected].

Last updated