Skip to content

RustFS

Con RustFS tienes un servicio de almacenamiento de objetos compatible con Amazon S3, diseñado para ser ligero, eficiente y muy simple de usar. Es una solución de código abierto escrita en Rust. Puedes instalarlo directamente en los sistemas operativos populares como: Windows, macOS o Linux.

Instalando RustFS

Desdel el sitio oficial puedes descargar el binario respectivo (por ejemplo, para [Windows). Sin embargo en automatizaciones es posible usar otros métodos de instalación.

Instalación de RustFS para Linux

Para Linux simplemente ejecutas el siguiente comando:

bash
curl -O https://rustfs.com/install_rustfs.sh && bash install_rustfs.sh

Instalación de RustFS para macOS

Para macOS, usando HomeBrew, puedes ejecutar lo siguiente:

bash
brew tap rustfs/homebrew-tap
brew install rustfs

Instalación de RustFS para contenedores (Docker)

Para Docker puedes ejecutar lo siguiente:

bash
docker pull rustfs/rustfs:latest
docker run -d \
  --name rustfs \
  -p 9000:9000 \
  -p 9001:9001 \
  -v $PWD/storage:/data \
  rustfs/rustfs:latest

El contenedor viene con consola web (UI) usando el puerto 9001, con usuario y clave rustfsadmin.
Como ventaja se pueden gestionar recipientes (buckets) y claves de acceso.

Usando RustFS localmente

Si has instalado el binario de RustFS, puedes lanzar el servicio ejecutando:

bash
rustfs server --address :9000 ./storage

Se indica el puerto y el volumen, por ejemplo, carpeta storage

Ejemplo con BunJS

Instalación del cliente

bash
bun add @aws-sdk/client-s3

Cliente básico

typescript
import { S3Client, PutObjectCommand, GetObjectCommand, ListBucketsCommand } from "@aws-sdk/client-s3";

const s3Client = new S3Client({
  endpoint: "http://localhost:9000",
  region: "us-east-1",
  credentials: {
    accessKeyId: "admin",
    secretAccessKey: "admin123"
  },
  forcePathStyle: true
});

// Listar buckets
async function listBuckets() {
  const response = await s3Client.send(new ListBucketsCommand({}));
  console.log("Buckets:", response.Buckets);
}

// Subir archivo
async function uploadFile(bucket: string, key: string, content: string) {
  await s3Client.send(new PutObjectCommand({
    Bucket: bucket,
    Key: key,
    Body: content
  }));
  console.log(`Archivo ${key} subido a ${bucket}`);
}

// Descargar archivo
async function downloadFile(bucket: string, key: string) {
  const response = await s3Client.send(new GetObjectCommand({
    Bucket: bucket,
    Key: key
  }));
  const content = await response.Body?.transformToString();
  console.log("Contenido:", content);
  return content;
}

// Uso
await listBuckets();
await uploadFile("my-bucket", "test.txt", "Hola desde BunJS!");
await downloadFile("my-bucket", "test.txt");

Servidor HTTP con RustFS

typescript
import { S3Client, PutObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3";

const s3 = new S3Client({
  endpoint: "http://localhost:9000",
  region: "us-east-1",
  credentials: {
    accessKeyId: "admin",
    secretAccessKey: "admin123"
  },
  forcePathStyle: true
});

const BUCKET = "uploads";

Bun.serve({
  port: 3000,
  async fetch(req) {
    const s = new URL(req.url);

    // Upload
    if (s.pathname === "/upload" && req.method === "POST") {
      const formData = await req.formData();
      const file = formData.get("file") as File;
      if (!file) return new Response("No file", { status: 400 });
      await s3.send(new PutObjectCommand({
        Bucket: BUCKET,
        Key: file.name,
        Body: Buffer.from(await file.arrayBuffer()),
        ContentType: file.type
      }));
      return Response.json({ message: "Uploaded", filename: file.name });
    }

    // Download
    if (s.pathname.startsWith("/download/")) {
      const filename = s.pathname.split("/download/")[1];
      try {
        const response = await s3.send(new GetObjectCommand({
          Bucket: BUCKET,
          Key: filename
        }));
        return new Response(response.Body as any, {
          headers: { "Content-Type": response.ContentType || "application/octet-stream" }
        });
      } catch (error) {
        return new Response("Not found", { status: 404 });
      }
    }

    return new Response("Garage API - /upload (POST) | /download/:filename (GET)");
  }
});

console.log("Server running on http://localhost:3000");

Uso:

bash
# Subir archivo
curl -F "[email protected]" http://localhost:3000/upload

# Descargar archivo
curl http://localhost:3000/download/documento.pdf -o descargado.pdf

© 2026 by César Arcila