48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
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()
|
|
}
|