Building with SettleMint/SDK Developer Guide

MinIO/S3 storage

Integrating MinIO/S3 storage in your SettleMint dApp

About

The SettleMint MinIO SDK provides a simple way to interact with MinIO object storage through the SettleMint platform. It enables you to easily store and retrieve files using MinIO's S3-compatible API in a secure and scalable manner.

API Reference

Functions

createPresignedUploadUrl()

createPresignedUploadUrl(client, fileName, path, bucket, expirySeconds): Promise<string>

Defined in: sdk/minio/src/helpers/functions.ts:243

Creates a presigned upload URL for direct browser uploads

Parameters
ParameterTypeDefault valueDescription
clientClientundefinedThe MinIO client to use
fileNamestringundefinedThe file name to use
pathstring""Optional path/folder
bucketstringDEFAULT_BUCKETOptional bucket name (defaults to DEFAULT_BUCKET)
expirySecondsnumber3600How long the URL should be valid for
Returns

Promise<string>

Presigned URL for PUT operation

Throws

Will throw an error if URL creation fails or client initialization fails

Example
import { createServerMinioClient, createPresignedUploadUrl } from "@settlemint/sdk-minio";
 
const { client } = createServerMinioClient({
  instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
  accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
  secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
});
 
// Generate the presigned URL on the server
const url = await createPresignedUploadUrl(client, "report.pdf", "documents/");
 
// Send the URL to the client/browser via HTTP response
return Response.json({ uploadUrl: url });
 
// Then in the browser:
const response = await fetch('/api/get-upload-url');
const { uploadUrl } = await response.json();
await fetch(uploadUrl, {
 method: 'PUT',
 headers: { 'Content-Type': 'application/pdf' },
 body: pdfFile
});

createServerMinioClient()

createServerMinioClient(options): object

Defined in: sdk/minio/src/minio.ts:23

Creates a MinIO client for server-side use with authentication.

Parameters
ParameterTypeDescription
options{ accessKey: string; instance: string; secretKey: string; }The server client options for configuring the MinIO client
options.accessKeystringThe MinIO access key used to authenticate with the MinIO server
options.instancestringThe URL of the MinIO instance to connect to
options.secretKeystringThe MinIO secret key used to authenticate with the MinIO server
Returns

object

An object containing the initialized MinIO client

NameTypeDefined in
clientClientsdk/minio/src/minio.ts:23
Throws

Will throw an error if not called on the server or if the options fail validation

Example
import { createServerMinioClient } from "@settlemint/sdk-minio";
 
const { client } = createServerMinioClient({
  instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
  accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
  secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
});
client.listBuckets();

deleteFile()

deleteFile(client, fileId, bucket): Promise<boolean>

Defined in: sdk/minio/src/helpers/functions.ts:196

Deletes a file from storage

Parameters
ParameterTypeDefault valueDescription
clientClientundefinedThe MinIO client to use
fileIdstringundefinedThe file identifier/path
bucketstringDEFAULT_BUCKETOptional bucket name (defaults to DEFAULT_BUCKET)
Returns

Promise<boolean>

Success status

Throws

Will throw an error if deletion fails or client initialization fails

Example
import { createServerMinioClient, deleteFile } from "@settlemint/sdk-minio";
 
const { client } = createServerMinioClient({
  instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
  accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
  secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
});
 
await deleteFile(client, "documents/report.pdf");

getFileById()

getFileById(client, fileId, bucket): Promise<FileMetadata>

Defined in: sdk/minio/src/helpers/functions.ts:123

Gets a single file by its object name

Parameters
ParameterTypeDefault valueDescription
clientClientundefinedThe MinIO client to use
fileIdstringundefinedThe file identifier/path
bucketstringDEFAULT_BUCKETOptional bucket name (defaults to DEFAULT_BUCKET)
Returns

Promise<FileMetadata>

File metadata with presigned URL

Throws

Will throw an error if the file doesn't exist or client initialization fails

Example
import { createServerMinioClient, getFileByObjectName } from "@settlemint/sdk-minio";
 
const { client } = createServerMinioClient({
  instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
  accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
  secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
});
 
const file = await getFileByObjectName(client, "documents/report.pdf");

getFilesList()

getFilesList(client, prefix, bucket): Promise<FileMetadata[]>

Defined in: sdk/minio/src/helpers/functions.ts:62

Gets a list of files with optional prefix filter

Parameters
ParameterTypeDefault valueDescription
clientClientundefinedThe MinIO client to use
prefixstring""Optional prefix to filter files (like a folder path)
bucketstringDEFAULT_BUCKETOptional bucket name (defaults to DEFAULT_BUCKET)
Returns

Promise<FileMetadata[]>

Array of file metadata objects

Throws

Will throw an error if the operation fails or client initialization fails

Example
import { createServerMinioClient, getFilesList } from "@settlemint/sdk-minio";
 
const { client } = createServerMinioClient({
  instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
  accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
  secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
});
 
const files = await getFilesList(client, "documents/");

uploadFile()

uploadFile(client, buffer, objectName, contentType, bucket): Promise<FileMetadata>

Defined in: sdk/minio/src/helpers/functions.ts:293

Uploads a buffer directly to storage

Parameters
ParameterTypeDefault valueDescription
clientClientundefinedThe MinIO client to use
bufferBufferundefinedThe buffer to upload
objectNamestringundefinedThe full object name/path
contentTypestringundefinedThe content type of the file
bucketstringDEFAULT_BUCKETOptional bucket name (defaults to DEFAULT_BUCKET)
Returns

Promise<FileMetadata>

The uploaded file metadata

Throws

Will throw an error if upload fails or client initialization fails

Example
import { createServerMinioClient, uploadBuffer } from "@settlemint/sdk-minio";
 
const { client } = createServerMinioClient({
  instance: process.env.SETTLEMINT_MINIO_ENDPOINT!,
  accessKey: process.env.SETTLEMINT_MINIO_ACCESS_KEY!,
  secretKey: process.env.SETTLEMINT_MINIO_SECRET_KEY!
});
 
const buffer = Buffer.from("Hello, world!");
const uploadedFile = await uploadFile(client, buffer, "documents/hello.txt", "text/plain");

Interfaces

FileMetadata

Defined in: sdk/minio/src/helpers/schema.ts:29

Type representing file metadata after validation.

Properties
PropertyTypeDescriptionDefined in
contentTypestringThe content type of the file.sdk/minio/src/helpers/schema.ts:41
etagstringThe ETag of the file.sdk/minio/src/helpers/schema.ts:56
idstringThe unique identifier for the file.sdk/minio/src/helpers/schema.ts:33
namestringThe name of the file.sdk/minio/src/helpers/schema.ts:37
sizenumberThe size of the file in bytes.sdk/minio/src/helpers/schema.ts:46
uploadedAtstringThe date and time the file was uploaded.sdk/minio/src/helpers/schema.ts:51
url?stringThe URL of the file.sdk/minio/src/helpers/schema.ts:61

Variables

DEFAULT_BUCKET

const DEFAULT_BUCKET: "uploads" = "uploads"

Defined in: sdk/minio/src/helpers/schema.ts:67

Default bucket name to use for file storage when none is specified.

Contributing

We welcome contributions from the community! Please check out our Contributing guide to learn how you can help improve the SettleMint SDK through bug reports, feature requests, documentation updates, or code contributions.

License

The SettleMint SDK is released under the FSL Software License. See the LICENSE file for more details.