Skip to main content

Installation

FPT Object Storage is a product developed based on the AWS S3 standard. Therefore, you can use all the tools and libraries developed for AWS S3 to interact with FPT Object Storage. Below are installation guides and sample connection configurations for some popular languages.

Python

With Python, you can use the boto3 library. This is Amazon's official library for Python. Installation

Copypip install boto3

Initialize connection

import boto3
s3_endpoint = "ENDPOINT"
s3_access_key_id = "ACCESS_KEY_ID"
s3_secret_access_key = "SECRET_KEY_ID"
s3 = boto3.resource(
"s3",
endpoint_url=s3_endpoint,
aws_access_key_id=s3_access_key_id,
aws_secret_access_key=s3_secret_access_key,
)

s3client = boto3.client(
"s3",
endpoint_url=s3_endpoint,
aws_access_key_id=s3_access_key_id,
aws_secret_access_key=s3_secret_access_key,
)

Where "ACCESS_KEY_ID", "SECRET_KEY_ID" and "ENDPOINT" are obtained from the FPT Unify Portal according to the instructions at this link/. Some basic examples

Copy# Create a new bucket
s3client.create_bucket(Bucket=bucket_name)
-------------------------------------------
s3client.delete_bucket(Bucket=bucket_name)
-------------------------------------------
s3client.put_object(Bucket=bucket_name, Key=object_key, Body=content)
-------------------------------------------
response = s3client.get_object(Bucket=bucket_name, Key=object_key)
object_content = response['Body'].read().decode('utf-8')
print(object_content)
-------------------------------------------
s3client.delete_object(Bucket=bucket_name, Key=object_key)

Full documentation Refer: https://boto3.amazonaws.com/v1/documentation/api/latest/index.html

Java

To use FPT Object Storage in Java, you can use supporting libraries such as AWS SDK for Java, MinIO or s3proxy. Below is a guide for using AWS SDK for Java, one of the most popular libraries to connect and work with FPT Object Storage: Installation

Copy// Create a maven project
// Add the following dependency to the pom.xml file:

<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.17.42</version> <!-- Make sure to use the latest version -->
</dependency>

Initialize connection

Copy// Change these values according to your S3-compatible account information
String accessKey = "ACCESS_KEY_ID";
String secretKey = "SECRET_KEY_ID";
String endpoint = "ENDPOINT";
String bucketName = "YOUR_BUCKET_NAME";
// Create S3 client
S3Client s3Client = S3Client.builder()
.endpointOverride(URI.create(endpoint))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey)))
.build();

Where "ACCESS_KEY_ID", "SECRET_KEY_ID" and "ENDPOINT" are obtained from the FPT Unify Portal according to the instructions at this link/. Some basic examples

Copyimport java.net.URI;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.ListObjectsRequest;
import software.amazon.awssdk.services.s3.model.ListObjectsResponse;
import software.amazon.awssdk.services.s3.model.S3Object;
public class S3Example {
public static void main(String[] args) {
// Change these values according to your S3-compatible account information
String accessKey = "ACCESS_KEY_ID";
String secretKey = "SECRET_KEY_ID";
String endpoint = "ENDPOINT";
String bucketName = "<YOUR_BUCKET_NAME>";
// Create S3 client
S3Client s3Client = S3Client.builder()
.endpointOverride(URI.create(endpoint))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey)))
.build();
// Perform S3 operations here, for example: list objects
ListObjectsRequest listObjectsRequest = ListObjectsRequest.builder()
.bucket(bucketName)
.build();
ListObjectsResponse listObjectsResponse = s3Client.listObjects(listObjectsRequest);
for (S3Object content: listObjectsResponse.contents()) {
System.out.println("Object Key: " + content.key());
}
// Close the client when done
s3Client.close();
}
}

Full documentation Refer: https://docs.aws.amazon.com/sdk-for-java/

C-Sharp

FPT Object Storage is designed to be compatible with Amazon S3, so you can use the S3 SDK for C# provided by AWS to interact with FPT Object Storage. Below are some basic instructions: Installation

Copy// Install via NuGet Package Manager
Install-Package AWSSDK -Version 2.3.55.2

Initialize connection

Copystring accessKey = "ACCESS_KEY_ID";
string secretKey = "SECRET_KEY_ID";
AmazonS3Config config = new AmazonS3Config();
config.ServiceURL = "<ENDPOINT>";
config.ForcePathStyle = true;
AmazonS3Client client = new AmazonS3Client(
accessKey,
secretKey,
config
);

Where "ACCESS_KEY_ID", "SECRET_KEY_ID" and "ENDPOINT" are obtained from the FPT Unify Portal according to the instructions at this link/. Some basic examples

Copy// Install via NuGet Package Manager
// Install-Package AWSSDK -Version 3.7.0
using Amazon.S3;
using Amazon.S3.Model;
class Program {
static void Main() {
// Initialize connection
string accessKey = "ACCESS_KEY_ID";
string secretKey = "SECRET_KEY_ID";
AmazonS3Config config = new AmazonS3Config {
ServiceURL = "ENDPOINT",
ForcePathStyle = true
};
using(AmazonS3Client client = new AmazonS3Client(accessKey, secretKey, config)) {
// Some basic examples
// Create a new bucket
string bucketName = "my-unique-bucket-name";
client.PutBucket(new PutBucketRequest {
BucketName = bucketName
});
// Delete bucket
client.DeleteBucket(new DeleteBucketRequest {
BucketName = bucketName
});
// Create a new object
string objectKey = "my-object-key";
string content = "Hello, world!";
client.PutObject(new PutObjectRequest {
BucketName = bucketName,
Key = objectKey,
ContentBody = content
});
// Read the content of the object
GetObjectResponse response = client.GetObject(new GetObjectRequest {
BucketName = bucketName,
Key = objectKey
});
using(var reader = new System.IO.StreamReader(response.ResponseStream)) {
string objectContent = reader.ReadToEnd();
Console.WriteLine(objectContent);
}
// Delete object
client.DeleteObject(new DeleteObjectRequest {
BucketName = bucketName,
Key = objectKey
});
}
}
}

Full documentation Refer: https://aws.amazon.com/sdk-for-net/

PHP

Installation

Copy// There are several ways to install the PHP SDK
// 1. Using Composer
php -d memory_limit=-1 composer.phar require aws/aws-sdk-php

// require composer autoload
<?php
require '/path/to/vendor/autoload.php';
?>

// 2. Using Packaged Phar
// Download at http://docs.aws.amazon.com/aws-sdk-php/v3/download/aws.phar and require into the script
<?php
require '/path/to/aws.phar';
?>

// 3. Using zip package
// Download at http://docs.aws.amazon.com/aws-sdk-php/v3/download/aws.zip and require into the script
<?php
require '/path/to/aws-autoloader.php';
?>

Initialize connection

Copy<?php
$accessKey = "ACCESS_KEY_ID";
$secretKey = "SECRET_KEY_ID";
$credentials = new Aws\Credentials\Credentials($accessKey, $secretKey);

$options = [
"version" => "latest",
"region" => "<REGION>",
"signature_version" => "v4",
"credentials" => $credentials,
"endpoint" => "<ENDPOINT>",
];

$s3Client = new Aws\S3\S3Client($options);

Where "ACCESS_KEY_ID", "SECRET_KEY_ID" and "ENDPOINT" are obtained from the FPT Unify Portal according to the instructions at this link/. Some basic examples

Copy// Install via Composer
// php -d memory_limit=-1 composer.phar require aws/aws-sdk-php
// Require composer autoload*
<?php require "/path/to/vendor/autoload.php"; ?>
<?php // Initialize connection

$accessKey = "ACCESS_KEY_ID";
$secretKey = "SECRET_KEY_ID";
$credentials = new Aws\Credentials\Credentials($accessKey, $secretKey);
$options = [
"version" => "latest",
"region" => "<REGION>",
"signature_version" => "v4",
"credentials" => $credentials,
"endpoint" => '"ENDPOINT"',
];
$s3Client = new Aws\S3\S3Client($options); // Some basic examples // Create a new bucket
$bucketName = "my-unique-bucket-name";
$s3Client->createBucket(["Bucket" => $bucketName]); // Delete bucket
$s3Client->deleteBucket(["Bucket" => $bucketName]); // Create a new object
$objectKey = "my-object-key";
$content = "Hello, world!";
$s3Client->putObject([
"Bucket" => $bucketName,
"Key" => $objectKey,
"Body" => $content,
]);
// Read the content of the object
$result = $s3Client->getObject(["Bucket" => $bucketName, "Key" => $objectKey]);
$objectContent = $result["Body"]->getContents();
echo $objectContent; // Delete object
$s3Client->deleteObject(["Bucket" => $bucketName, "Key" => $objectKey]);
?>

Full documentation Refer: https://docs.aws.amazon.com/sdk-for-php/

Javascript

Installation

Copy// To install the Javascript SDK
// 1. Download the sdk release from: https://github.com/aws/aws-sdk-js/releases
// 2. Extract the dist/ folder of the sdk
// 3. Use the sdk file for the browser by embedding it into the html file

Initialize connection

CopyaccessKey = "ACCESS_KEY_ID";
secretKey = "SECRET_KEY_ID";
AWS.config.update({
accessKeyId: accessKey,
secretAccessKey: secretKey,
region: '<REGION>',
endpoint: '<ENDPOINT>',
apiVersions: {
s3: '2006-03-01'
}
})
const s3 = new AWS.S3()

Where "ACCESS_KEY_ID", "SECRET_KEY_ID" and "ENDPOINT" are obtained from the FPT Unify Portal according to the instructions at this link/. Some basic examples

Copy<!-- Install the Javascript SDK -->
<!-- 1. Download the sdk release from: https://github.com/aws/aws-sdk-js/releases -->
<!-- 2. Extract the dist/ folder of the sdk -->
<!-- 3. Use the sdk file for the browser by embedding it into the HTML file -->
<
script >
// Initialize connection
var accessKey = "<ACCESS_KEY_ID>";
var secretKey = "<SECRET_KEY_ID>";

AWS.config.update({
accessKeyId: accessKey,
secretAccessKey: secretKey,
region: '<REGION>',
endpoint: '<ENDPOINT>',
apiVersions: {
s3: '2006-03-01'
}
});

var s3 = new AWS.S3();

// Some basic examples

// Create a new bucket
var bucketName = "my-unique-bucket-name";
s3.createBucket({
Bucket: bucketName
}, function(err, data) {
if (err) console.log(err, err.stack);
else console.log("Bucket created:", data);
});

// Delete bucket
s3.deleteBucket({
Bucket: bucketName
}, function(err, data) {
if (err) console.log(err, err.stack);
else console.log("Bucket deleted:", data);
});

// Create a new object
var objectKey = "my-object-key";
var content = "Hello, world!";
s3.putObject({
Bucket: bucketName,
Key: objectKey,
Body: content
}, function(err, data) {
if (err) console.log(err, err.stack);
else console.log("Object created:", data);
});

// Read the content of the object
s3.getObject({
Bucket: bucketName,
Key: objectKey
}, function(err, data) {
if (err) console.log(err, err.stack);
else console.log("Object content:", data.Body.toString('utf-8'));
});

// Delete object
s3.deleteObject({
Bucket: bucketName,
Key: objectKey
}, function(err, data) {
if (err) console.log(err, err.stack);
else console.log("Object deleted:", data);
}); <
/script>

Full documentation Refer: https://docs.aws.amazon.com/sdk-for-javascript/

NodeJS

Installation

Copynpm install aws-sdk@2.x

Initialize connection

Copyconst AWS = require('aws-sdk')
AWS.config.update({
accessKeyId: `"ACCESS_KEY_ID" `,
secretAccessKey: `"SECRET_KEY_ID"`,
region: '<REGION>',
endpoint: '"ENDPOINT"',
apiVersions: {
s3: '2006-03-01'
},
logger: process.stdout
})

Where "ACCESS_KEY_ID", "SECRET_KEY_ID" and "ENDPOINT" are obtained from the FPT Unify Portal according to the instructions at this link/. Some basic examples

Copy// Installation
// npm install aws-sdk@2.x

const AWS = require('aws-sdk');

// Initialize connection
AWS.config.update({
accessKeyId: '"ACCESS_KEY_ID"',
secretAccessKey: '"SECRET_KEY_ID"',
region: '<REGION>',
endpoint: '"ENDPOINT"',
apiVersions: {
s3: '2006-03-01',
},
logger: process.stdout,
});

const s3 = new AWS.S3();

// Some basic examples

// Create a new bucket
const bucketName = 'my-unique-bucket-name';
s3.createBucket({ Bucket: bucketName }, (err, data) => {
if (err) console.error(err, err.stack);
else console.log('Bucket created:', data);
});

// Delete bucket
s3.deleteBucket({ Bucket: bucketName }, (err, data) => {
if (err) console.error(err, err.stack);
else console.log('Bucket deleted:', data);
});

// Create a new object
const objectKey = 'my-object-key';
const content = 'Hello, world!';
s3.putObject({ Bucket: bucketName, Key: objectKey, Body: content }, (err, data) => {
if (err) console.error(err, err.stack);
else console.log('Object created:', data);
});

// Read the content of the object
s3.getObject({ Bucket: bucketName, Key: objectKey }, (err, data) => {
if (err) console.error(err, err.stack);
else console.log('Object content:', data.Body.toString('utf-8'));
});

// Delete object
s3.deleteObject({ Bucket: bucketName, Key: objectKey }, (err, data) => {
if (err) console.error(err, err.stack);
else console.log('Object deleted:', data);
});

Full documentation Refer: https://github.com/aws/aws-sdk-js/

Go

Installation

Copygo get "github.com/aws/aws-sdk-go/aws"

Initialize connection

Copys3Config := &aws.Config{
Credentials: credentials.NewStaticCredentials("ACCESS_KEY_ID", "SECRET_KEY_ID", ""),
Endpoint: aws.String("ENDPOINT"),
Region: aws.String("REGION"),
}
newSession := session.New(s3Config)
Client = s3.New(newSession)

Where "ACCESS_KEY_ID", "SECRET_KEY_ID" and "ENDPOINT" are obtained from the FPT Unify Portal according to the instructions at this link/. Some basic examples

Copypackage main

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
"log"
)

var Client *s3.S3

func main() {
// Initialize connection
s3Config := &aws.Config{
Credentials: credentials.NewStaticCredentials("ACCESS_KEY_ID", "SECRET_KEY_ID", ""),
Endpoint: aws.String("ENDPOINT"),
Region: aws.String("REGION"),
}
newSession := session.New(s3Config)
Client = s3.New(newSession)

// Some basic examples

// Create a new bucket
bucketName := "my-unique-bucket-name"
_, err := Client.CreateBucket(&s3.CreateBucketInput{
Bucket: aws.String(bucketName),
})
if err != nil {
log.Fatal(err)
}
log.Println("Bucket created:", bucketName)

// Delete bucket
_, err = Client.DeleteBucket(&s3.DeleteBucketInput{
Bucket: aws.String(bucketName),
})
if err != nil {
log.Fatal(err)
}
log.Println("Bucket deleted:", bucketName)

// Create a new object
objectKey := "my-object-key"
content := "Hello, world!"
_, err = Client.PutObject(&s3.PutObjectInput{
Bucket: aws.String(bucketName),
Key: aws.String(objectKey),
Body: aws.String(content),
})
if err != nil {
log.Fatal(err)
}
log.Println("Object created:", objectKey)

// Read the content of the object
result, err := Client.GetObject(&s3.GetObjectInput{
Bucket: aws.String(bucketName),
Key: aws.String(objectKey),
})
if err != nil {
log.Fatal(err)
}
log.Println("Object content:", result.Body)

// Delete object
_, err = Client.DeleteObject(&s3.DeleteObjectInput{
Bucket: aws.String(bucketName),
Key: aws.String(objectKey),
})
if err != nil {
log.Fatal(err)
}
log.Println("Object deleted:", objectKey)
}

Full documentation Refer: https://docs.aws.amazon.com/sdk-for-go/