Skip to main content

SDKs

Vietnix Cloud S3 Storage is fully compatible with the S3 API, allowing you to use a wide range of official AWS SDKs and community libraries in various programming languages. Below are examples of how to connect and perform basic operations with some popular SDKs.

1. Python (Boto3)

import boto3

s3 = boto3.client(
's3',
endpoint_url='https://s3.vn-hcm-1.vietnix.cloud',
aws_access_key_id='YOUR_ACCESS_KEY',
aws_secret_access_key='YOUR_SECRET_KEY',
region_name='vn-hcm-1'
)

# List buckets
response = s3.list_buckets()
print(response['Buckets'])

# Upload a file
s3.upload_file('local-file.txt', 'your-bucket-name', 'remote-file.txt')

2. Node.js (AWS SDK v3)

const { S3Client, ListBucketsCommand, PutObjectCommand } = require('@aws-sdk/client-s3');

const s3 = new S3Client({
endpoint: 'https://s3.vn-hcm-1.vietnix.cloud',
region: 'vn-hcm-1',
credentials: {
accessKeyId: 'YOUR_ACCESS_KEY',
secretAccessKey: 'YOUR_SECRET_KEY'
},
forcePathStyle: true
});

// List buckets
s3.send(new ListBucketsCommand({})).then(data => console.log(data.Buckets));

// Upload a file
const fs = require('fs');
const fileStream = fs.createReadStream('local-file.txt');
s3.send(new PutObjectCommand({
Bucket: 'your-bucket-name',
Key: 'remote-file.txt',
Body: fileStream
}));

3. Go (AWS SDK v2)

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"
)

sess := session.Must(session.NewSession(&aws.Config{
Region: aws.String("vn-hcm-1"),
Endpoint: aws.String("https://s3.vn-hcm-1.vietnix.cloud"),
S3ForcePathStyle: aws.Bool(true),
Credentials: credentials.NewStaticCredentials("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY", ""),
}))

svc := s3.New(sess)

// List buckets
result, _ := svc.ListBuckets(nil)
for _, b := range result.Buckets {
fmt.Println(*b.Name)
}

// Upload a file
file, _ := os.Open("local-file.txt")
defer file.Close()
svc.PutObject(&s3.PutObjectInput{
Bucket: aws.String("your-bucket-name"),
Key: aws.String("remote-file.txt"),
Body: file,
})

4. Java (AWS SDK v2)

S3Client s3 = S3Client.builder()
.endpointOverride(URI.create("https://s3.vn-hcm-1.vietnix.cloud"))
.region(Region.of("vn-hcm-1"))
.credentialsProvider(StaticCredentialsProvider.create(
AwsBasicCredentials.create("YOUR_ACCESS_KEY", "YOUR_SECRET_KEY")))
.forcePathStyle(true)
.build();

// List buckets
ListBucketsResponse buckets = s3.listBuckets();
buckets.buckets().forEach(b -> System.out.println(b.name()));

// Upload a file
s3.putObject(PutObjectRequest.builder()
.bucket("your-bucket-name")
.key("remote-file.txt")
.build(),
RequestBody.fromFile(Paths.get("local-file.txt")));

5. PHP (AWS SDK for PHP)

  • Install AWS SDK for PHP via Composer
composer require aws/aws-sdk-php
  • PHP Code Example
require 'vendor/autoload.php';

use Aws\S3\S3Client;
use Aws\Exception\AwsException;

// Your Vietnix Cloud S3 credentials (get from Vietnix panel)
$accessKey = 'YOUR_ACCESS_KEY'; // e.g. AKIAxxxxxxxxxxxxxxxx
$secretKey = 'YOUR_SECRET_KEY'; // e.g. wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY

// Vietnix S3 configuration
$s3Client = new S3Client([
'version' => 'latest', // or '2006-03-01'
'region' => 'auto', // Can be anything, Vietnix ignores it
'endpoint' => 'https://s3.vn-hcm-1.vietnix.cloud',
'credentials' => [
'key' => $accessKey,
'secret' => $secretKey,
],
// Important options for non-AWS endpoints
'use_path_style_endpoint' => true, // Very important for Vietnix
'bucket_endpoint' => false,
]);

// Test: List all buckets
try {
$result = $s3Client->listBuckets();
echo "Buckets:\n";
foreach ($result['Buckets'] as $bucket) {
echo "- " . $bucket['Name'] . " (created: " . $bucket['CreationDate'] . ")\n";
}
} catch (AwsException $e) {
echo "Error: " . $e->getMessage();
}

// Example: Upload a file
$bucketName = 'your-bucket-name'; // Must already exist in Vietnix panel
$key = 'test-folder/hello-world.txt';
$filePath = __DIR__ . '/hello.txt';

try {
$result = $s3Client->putObject([
'Bucket' => $bucketName,
'Key' => $key,
'Body' => fopen($filePath, 'r'),
'ACL' => 'public-read', // optional
]);

echo "File uploaded successfully!\n";
echo "URL: " . $result->get('ObjectURL') . "\n";
} catch (AwsException $e) {
echo "Upload failed: " . $e->getMessage();
}

info
  • Replace YOUR_ACCESS_KEY, YOUR_SECRET_KEY, and your-bucket-name with your actual credentials and bucket name.
  • Always keep your credentials secure and rotate them regularly.
  • For advanced usage, refer to each SDK’s official documentation.