feat: add azblob client implementation for file uploads

This commit is contained in:
2026-04-21 10:01:42 -05:00
parent 16c232762e
commit 8217b13d08
3 changed files with 57 additions and 4 deletions

47
scripts/az-blob/main.go Normal file
View File

@@ -0,0 +1,47 @@
package main
import (
"context"
"fmt"
"log"
"math/rand"
"sync"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
func main() {
accountKey := "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw=="
connStr := fmt.Sprintf("DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=%s;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;", accountKey)
containerName := "pruebas"
// 1. Crear cliente
client, err := azblob.NewClientFromConnectionString(connStr, nil)
if err != nil {
log.Fatalf("Error creando cliente: %v", err)
}
ctx := context.Background()
var wg sync.WaitGroup
// 3. Subir archivos
for i := 1; i <= 10; i++ {
wg.Add(1)
go func(id int) {
defer wg.Done()
blobName := fmt.Sprintf("archivo-%d.txt", id)
content := fmt.Sprintf("Contenido aleatorio: %d", rand.Intn(100000))
// Usamos UploadBuffer
_, err := client.UploadBuffer(ctx, containerName, blobName, []byte(content), nil)
if err != nil {
log.Printf("Fallo al subir %s: %v", blobName, err)
} else {
fmt.Printf("Subido exitosamente: %s\n", blobName)
}
}(i)
}
wg.Wait()
}