SDK reference
Because FPT Object Storage is compatible with the AWS S3 API, your application can use the official AWS SDKs to read and write data. Each section below shows how to install the SDK, create a client, and run basic bucket and object operations.
To manage data without writing code, use an S3 client instead. See Connect with S3 clients.
Before you start
Every example uses the following placeholders. Replace them with your own values from the Portal. See Manage Access Keys.
| Placeholder | Value |
|---|---|
YOUR_ACCESS_KEY | Access Key. |
YOUR_SECRET_KEY | Secret Key. |
YOUR_ENDPOINT | Endpoint of the region, as a full URL including https://, for example https://s3-hcm04.fptcloud.com. |
YOUR_REGION | Region of the bucket. |
Never hard-code an Admin Access Key in source code you share or deploy. Use a SubUser or IAM User key with only the permissions the application needs, and load it from environment variables or a secret store.
SDK versions released from 2025 onward add data-integrity checksums to upload requests by default. If uploads fail with errors such as XAmzContentSHA256Mismatch or MissingContentLength, set the request checksum calculation option of the SDK to when_required. See Troubleshooting.
Python
Use boto3, the official AWS SDK for Python.
Installation
pip install boto3
Initialize a client
import boto3
s3_endpoint = "YOUR_ENDPOINT"
s3_access_key_id = "YOUR_ACCESS_KEY"
s3_secret_access_key = "YOUR_SECRET_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,
)
s3 = boto3.resource(
"s3",
endpoint_url=s3_endpoint,
aws_access_key_id=s3_access_key_id,
aws_secret_access_key=s3_secret_access_key,
)
Basic examples
bucket_name = "my-unique-bucket-name"
object_key = "my-object-key"
s3client.create_bucket(Bucket=bucket_name)
s3client.put_object(Bucket=bucket_name, Key=object_key, Body="Hello, world!")
response = s3client.get_object(Bucket=bucket_name, Key=object_key)
print(response["Body"].read().decode("utf-8"))
s3client.delete_object(Bucket=bucket_name, Key=object_key)
s3client.delete_bucket(Bucket=bucket_name)
Full documentation: boto3 documentation.
Java
Use the AWS SDK for Java 2.x.
Installation
Add the dependency to the pom.xml file of your Maven project.
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.17.42</version> <!-- Use the latest 2.x version -->
</dependency>
Initialize a client
String accessKey = "YOUR_ACCESS_KEY";
String secretKey = "YOUR_SECRET_KEY";
String endpoint = "YOUR_ENDPOINT";
String region = "YOUR_REGION";
S3Client s3Client = S3Client.builder()
.endpointOverride(URI.create(endpoint))
.region(Region.of(region))
.credentialsProvider(StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKey, secretKey)))
.serviceConfiguration(S3Configuration.builder().pathStyleAccessEnabled(true).build())
.build();
Basic examples
import java.net.URI;
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
import software.amazon.awssdk.core.sync.RequestBody;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.S3Configuration;
import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
import software.amazon.awssdk.services.s3.model.DeleteBucketRequest;
import software.amazon.awssdk.services.s3.model.DeleteObjectRequest;
import software.amazon.awssdk.services.s3.model.GetObjectRequest;
import software.amazon.awssdk.services.s3.model.ListObjectsV2Request;
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
import software.amazon.awssdk.services.s3.model.S3Object;
public class S3Example {
public static void main(String[] args) {
String bucketName = "my-unique-bucket-name";
String objectKey = "my-object-key";
S3Client s3Client = S3Client.builder()
.endpointOverride(URI.create("YOUR_ENDPOINT"))
.region(Region.of("YOUR_REGION"))
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY")))
.serviceConfiguration(S3Configuration.builder().pathStyleAccessEnabled(true).build())
.build();
// Create a bucket
s3Client.createBucket(CreateBucketRequest.builder().bucket(bucketName).build());
// Upload an object
s3Client.putObject(
PutObjectRequest.builder().bucket(bucketName).key(objectKey).build(),
RequestBody.fromString("Hello, world!"));
// List objects
for (S3Object object : s3Client.listObjectsV2(
ListObjectsV2Request.builder().bucket(bucketName).build()).contents()) {
System.out.println("Object Key: " + object.key());
}
// Read an object
String content = s3Client.getObjectAsBytes(
GetObjectRequest.builder().bucket(bucketName).key(objectKey).build()).asUtf8String();
System.out.println(content);
// Delete the object, then the empty bucket
s3Client.deleteObject(DeleteObjectRequest.builder().bucket(bucketName).key(objectKey).build());
s3Client.deleteBucket(DeleteBucketRequest.builder().bucket(bucketName).build());
s3Client.close();
}
}
Full documentation: AWS SDK for Java.
C#
Use the AWS SDK for .NET.
Installation
dotnet add package AWSSDK.S3
Initialize a client
var config = new AmazonS3Config
{
ServiceURL = "YOUR_ENDPOINT",
ForcePathStyle = true
};
var client = new AmazonS3Client("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY", config);
Basic examples
using System;
using System.IO;
using System.Threading.Tasks;
using Amazon.S3;
using Amazon.S3.Model;
class Program
{
static async Task Main()
{
var config = new AmazonS3Config
{
ServiceURL = "YOUR_ENDPOINT",
ForcePathStyle = true
};
using var client = new AmazonS3Client("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY", config);
string bucketName = "my-unique-bucket-name";
string objectKey = "my-object-key";
// Create a bucket
await client.PutBucketAsync(new PutBucketRequest { BucketName = bucketName });
// Upload an object
await client.PutObjectAsync(new PutObjectRequest
{
BucketName = bucketName,
Key = objectKey,
ContentBody = "Hello, world!"
});
// Read an object
using (GetObjectResponse response = await client.GetObjectAsync(bucketName, objectKey))
using (var reader = new StreamReader(response.ResponseStream))
{
Console.WriteLine(await reader.ReadToEndAsync());
}
// Delete the object, then the empty bucket
await client.DeleteObjectAsync(bucketName, objectKey);
await client.DeleteBucketAsync(bucketName);
}
}
Full documentation: AWS SDK for .NET.
PHP
Use the AWS SDK for PHP.
Installation
composer require aws/aws-sdk-php
Initialize a client
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
$s3Client = new S3Client([
'version' => 'latest',
'region' => 'YOUR_REGION',
'endpoint' => 'YOUR_ENDPOINT',
'use_path_style_endpoint' => true,
'credentials' => [
'key' => 'YOUR_ACCESS_KEY',
'secret' => 'YOUR_SECRET_KEY',
],
]);
Basic examples
<?php
require 'vendor/autoload.php';
use Aws\S3\S3Client;
$s3Client = new S3Client([
'version' => 'latest',
'region' => 'YOUR_REGION',
'endpoint' => 'YOUR_ENDPOINT',
'use_path_style_endpoint' => true,
'credentials' => [
'key' => 'YOUR_ACCESS_KEY',
'secret' => 'YOUR_SECRET_KEY',
],
]);
$bucketName = 'my-unique-bucket-name';
$objectKey = 'my-object-key';
// Create a bucket
$s3Client->createBucket(['Bucket' => $bucketName]);
// Upload an object
$s3Client->putObject([
'Bucket' => $bucketName,
'Key' => $objectKey,
'Body' => 'Hello, world!',
]);
// Read an object
$result = $s3Client->getObject(['Bucket' => $bucketName, 'Key' => $objectKey]);
echo $result['Body']->getContents();
// Delete the object, then the empty bucket
$s3Client->deleteObject(['Bucket' => $bucketName, 'Key' => $objectKey]);
$s3Client->deleteBucket(['Bucket' => $bucketName]);
Full documentation: AWS SDK for PHP.
JavaScript in the browser
In a browser, do not create an S3 client with your Access Key — anyone who opens the page can read it. Instead, have your backend generate a short-lived presigned URL, then upload or download directly from the browser with that URL. Configure Bucket CORS to allow the origin of your website.
Installation
npm install @aws-sdk/client-s3 @aws-sdk/s3-request-presigner
Initialize a client
// Backend (Node.js, ES module)
import { S3Client } from '@aws-sdk/client-s3';
const s3 = new S3Client({
region: 'YOUR_REGION',
endpoint: 'YOUR_ENDPOINT',
forcePathStyle: true,
credentials: {
accessKeyId: 'YOUR_ACCESS_KEY',
secretAccessKey: 'YOUR_SECRET_KEY',
},
});
Basic examples
// Backend: create a presigned upload URL that is valid for 15 minutes
import { PutObjectCommand } from '@aws-sdk/client-s3';
import { getSignedUrl } from '@aws-sdk/s3-request-presigner';
const uploadUrl = await getSignedUrl(
s3,
new PutObjectCommand({ Bucket: 'my-unique-bucket-name', Key: 'uploads/photo.jpg' }),
{ expiresIn: 900 },
);
// Browser: upload the selected file with the presigned URL
const file = document.querySelector('input[type="file"]').files[0];
await fetch(uploadUrl, { method: 'PUT', body: file });
Full documentation: AWS SDK for JavaScript v3.
Node.js
Use the AWS SDK for JavaScript v3. Version 2 (aws-sdk) has reached end of support.
Installation
npm install @aws-sdk/client-s3
Initialize a client
const { S3Client } = require('@aws-sdk/client-s3');
const s3 = new S3Client({
region: 'YOUR_REGION',
endpoint: 'YOUR_ENDPOINT',
forcePathStyle: true,
credentials: {
accessKeyId: 'YOUR_ACCESS_KEY',
secretAccessKey: 'YOUR_SECRET_KEY',
},
});
Basic examples
const {
S3Client,
CreateBucketCommand,
PutObjectCommand,
GetObjectCommand,
DeleteObjectCommand,
DeleteBucketCommand,
} = require('@aws-sdk/client-s3');
const s3 = new S3Client({
region: 'YOUR_REGION',
endpoint: 'YOUR_ENDPOINT',
forcePathStyle: true,
credentials: {
accessKeyId: 'YOUR_ACCESS_KEY',
secretAccessKey: 'YOUR_SECRET_KEY',
},
});
async function main() {
const Bucket = 'my-unique-bucket-name';
const Key = 'my-object-key';
// Create a bucket
await s3.send(new CreateBucketCommand({ Bucket }));
// Upload an object
await s3.send(new PutObjectCommand({ Bucket, Key, Body: 'Hello, world!' }));
// Read an object
const response = await s3.send(new GetObjectCommand({ Bucket, Key }));
console.log('Object content:', await response.Body.transformToString());
// Delete the object, then the empty bucket
await s3.send(new DeleteObjectCommand({ Bucket, Key }));
await s3.send(new DeleteBucketCommand({ Bucket }));
}
main().catch(console.error);
Full documentation: AWS SDK for JavaScript v3.
Go
Use the AWS SDK for Go v2. Version 1 (aws-sdk-go) has reached end of support.
Installation
go get github.com/aws/aws-sdk-go-v2/aws github.com/aws/aws-sdk-go-v2/credentials github.com/aws/aws-sdk-go-v2/service/s3
Initialize a client
client := s3.New(s3.Options{
Region: "YOUR_REGION",
BaseEndpoint: aws.String("YOUR_ENDPOINT"),
UsePathStyle: true,
Credentials: credentials.NewStaticCredentialsProvider("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY", ""),
})
Basic examples
package main
import (
"context"
"io"
"log"
"strings"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/credentials"
"github.com/aws/aws-sdk-go-v2/service/s3"
)
func main() {
ctx := context.Background()
client := s3.New(s3.Options{
Region: "YOUR_REGION",
BaseEndpoint: aws.String("YOUR_ENDPOINT"),
UsePathStyle: true,
Credentials: credentials.NewStaticCredentialsProvider("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY", ""),
})
bucketName := "my-unique-bucket-name"
objectKey := "my-object-key"
// Create a bucket
if _, err := client.CreateBucket(ctx, &s3.CreateBucketInput{Bucket: aws.String(bucketName)}); err != nil {
log.Fatal(err)
}
// Upload an object
if _, err := client.PutObject(ctx, &s3.PutObjectInput{
Bucket: aws.String(bucketName),
Key: aws.String(objectKey),
Body: strings.NewReader("Hello, world!"),
}); err != nil {
log.Fatal(err)
}
// Read an object
out, err := client.GetObject(ctx, &s3.GetObjectInput{
Bucket: aws.String(bucketName),
Key: aws.String(objectKey),
})
if err != nil {
log.Fatal(err)
}
data, err := io.ReadAll(out.Body)
out.Body.Close()
if err != nil {
log.Fatal(err)
}
log.Println("Object content:", string(data))
// Delete the object, then the empty bucket
if _, err := client.DeleteObject(ctx, &s3.DeleteObjectInput{
Bucket: aws.String(bucketName),
Key: aws.String(objectKey),
}); err != nil {
log.Fatal(err)
}
if _, err := client.DeleteBucket(ctx, &s3.DeleteBucketInput{Bucket: aws.String(bucketName)}); err != nil {
log.Fatal(err)
}
}
Full documentation: AWS SDK for Go v2.