tessl install tessl/golang-github-com--azure--azure-sdk-for-go--sdk--storage--azblob@1.6.0Azure Blob Storage SDK for Go providing comprehensive blob storage operations including uploads, downloads, container management, and advanced features like leases and SAS generation
The root azblob.Client provides convenient methods for common blob storage operations without requiring navigation through the client hierarchy. It wraps a service client and delegates operations to the appropriate specialized clients.
package azblob
type Client struct {
// contains filtered or unexported fields
}Creates a client with Azure AD token credential (recommended for production).
func NewClient(serviceURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error)Parameters:
serviceURL: The URL of the storage account (e.g., https://<account>.blob.core.windows.net/)cred: An Azure AD credential, typically obtained via the azidentity moduleoptions: Client options; pass nil to accept defaultsExample:
import (
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
)
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
// handle error
}
client, err := azblob.NewClient("https://myaccount.blob.core.windows.net/", cred, nil)
if err != nil {
// handle error
}Creates a client with shared key authentication.
func NewClientWithSharedKeyCredential(serviceURL string, cred *SharedKeyCredential, options *ClientOptions) (*Client, error)Parameters:
serviceURL: The URL of the storage accountcred: A SharedKeyCredential created with the storage account name and access keyoptions: Client options; pass nil to accept defaultsExample:
import "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
cred, err := azblob.NewSharedKeyCredential("myaccount", "myaccesskey")
if err != nil {
// handle error
}
client, err := azblob.NewClientWithSharedKeyCredential(
"https://myaccount.blob.core.windows.net/",
cred,
nil,
)Creates a client from a connection string.
func NewClientFromConnectionString(connectionString string, options *ClientOptions) (*Client, error)Parameters:
connectionString: Azure Storage account connection stringoptions: Client options; pass nil to accept defaultsExample:
connectionString := "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey;EndpointSuffix=core.windows.net"
client, err := azblob.NewClientFromConnectionString(connectionString, nil)Creates a client without credentials for anonymous access or when using SAS URLs.
func NewClientWithNoCredential(serviceURL string, options *ClientOptions) (*Client, error)Parameters:
serviceURL: The URL of the storage account (may include SAS token)options: Client options; pass nil to accept defaultsExample:
// With SAS token
serviceURL := "https://myaccount.blob.core.windows.net/?sv=2021-08-06&ss=b&srt=sco&sp=rwdlac&se=..."
client, err := azblob.NewClientWithNoCredential(serviceURL, nil)type ClientOptions struct {
// Telemetry configures the built-in telemetry policy behavior
Telemetry policy.TelemetryOptions
// Transport sets the transport for HTTP requests
Transport policy.Transporter
// Retry configures the built-in retry policy behavior
Retry policy.RetryOptions
// PerCallPolicies contains custom policies to inject into the pipeline (executed once per request)
PerCallPolicies []policy.Policy
// PerRetryPolicies contains custom policies to inject into the pipeline (executed once per retry)
PerRetryPolicies []policy.Policy
// InsecureAllowCredentialWithHTTP enables authenticated requests over HTTP (not recommended for production)
InsecureAllowCredentialWithHTTP bool
// DisableRPRegistration disables automatic Azure resource provider registration
DisableRPRegistration bool
}Returns the service URL for the client.
func (c *Client) URL() stringReturns the embedded service client for accessing service-level operations.
func (c *Client) ServiceClient() *service.ClientCreates a new container under the storage account.
func (c *Client) CreateContainer(ctx context.Context, containerName string, o *CreateContainerOptions) (CreateContainerResponse, error)Parameters:
ctx: Context for cancellation and deadlinescontainerName: Name of the container to createo: Optional parameters (pass nil for defaults)Example:
import "context"
ctx := context.Background()
resp, err := client.CreateContainer(ctx, "mycontainer", nil)
if err != nil {
// handle error
}Deletes a container from the storage account.
func (c *Client) DeleteContainer(ctx context.Context, containerName string, o *DeleteContainerOptions) (DeleteContainerResponse, error)Parameters:
ctx: Context for cancellation and deadlinescontainerName: Name of the container to deleteo: Optional parameters (pass nil for defaults)Returns a pager for listing containers in the storage account.
func (c *Client) NewListContainersPager(o *ListContainersOptions) *runtime.Pager[ListContainersResponse]Parameters:
o: Optional parameters for filtering and controlling the listingExample:
pager := client.NewListContainersPager(nil)
for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
// handle error
}
for _, container := range page.ContainerItems {
fmt.Printf("Container: %s\n", *container.Name)
}
}Deletes a blob from a container.
func (c *Client) DeleteBlob(ctx context.Context, containerName string, blobName string, o *DeleteBlobOptions) (DeleteBlobResponse, error)Parameters:
ctx: Context for cancellation and deadlinescontainerName: Name of the container containing the blobblobName: Name of the blob to deleteo: Optional parameters (pass nil for defaults)Returns a pager for listing blobs in a container (flat listing).
func (c *Client) NewListBlobsFlatPager(containerName string, o *ListBlobsFlatOptions) *runtime.Pager[ListBlobsFlatResponse]Parameters:
containerName: Name of the containero: Optional parameters for filtering and controlling the listingExample:
pager := client.NewListBlobsFlatPager("mycontainer", nil)
for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
// handle error
}
for _, blob := range page.Segment.BlobItems {
fmt.Printf("Blob: %s, Size: %d\n", *blob.Name, *blob.Properties.ContentLength)
}
}Uploads a byte buffer to a block blob using parallel block uploads.
func (c *Client) UploadBuffer(ctx context.Context, containerName string, blobName string, buffer []byte, o *UploadBufferOptions) (UploadBufferResponse, error)Parameters:
ctx: Context for cancellation and deadlinescontainerName: Name of the containerblobName: Name of the blob to createbuffer: Byte buffer containing the data to uploado: Optional parameters (pass nil for defaults)Example:
data := []byte("Hello, Azure Blob Storage!")
resp, err := client.UploadBuffer(ctx, "mycontainer", "myblob.txt", data, nil)
if err != nil {
// handle error
}Uploads a file to a block blob using parallel block uploads.
func (c *Client) UploadFile(ctx context.Context, containerName string, blobName string, file *os.File, o *UploadFileOptions) (UploadFileResponse, error)Parameters:
ctx: Context for cancellation and deadlinescontainerName: Name of the containerblobName: Name of the blob to createfile: Open file handle to uploado: Optional parameters (pass nil for defaults)Example:
import "os"
file, err := os.Open("localfile.txt")
if err != nil {
// handle error
}
defer file.Close()
resp, err := client.UploadFile(ctx, "mycontainer", "remotefile.txt", file, nil)Uploads data from an io.Reader to a block blob using parallel block uploads.
func (c *Client) UploadStream(ctx context.Context, containerName string, blobName string, body io.Reader, o *UploadStreamOptions) (UploadStreamResponse, error)Parameters:
ctx: Context for cancellation and deadlinescontainerName: Name of the containerblobName: Name of the blob to createbody: Reader providing the data to uploado: Optional parameters (pass nil for defaults)Downloads a blob to a byte buffer with parallel downloads.
func (c *Client) DownloadBuffer(ctx context.Context, containerName string, blobName string, buffer []byte, o *DownloadBufferOptions) (int64, error)Parameters:
ctx: Context for cancellation and deadlinescontainerName: Name of the containerblobName: Name of the blob to downloadbuffer: Pre-allocated buffer to receive the datao: Optional parameters (pass nil for defaults)Returns: Number of bytes downloaded
Example:
buffer := make([]byte, 1024*1024) // 1 MB buffer
bytesDownloaded, err := client.DownloadBuffer(ctx, "mycontainer", "myblob.txt", buffer, nil)
if err != nil {
// handle error
}
data := buffer[:bytesDownloaded]Downloads a blob to a file with parallel downloads.
func (c *Client) DownloadFile(ctx context.Context, containerName string, blobName string, file *os.File, o *DownloadFileOptions) (int64, error)Parameters:
ctx: Context for cancellation and deadlinescontainerName: Name of the containerblobName: Name of the blob to downloadfile: Open file handle to write too: Optional parameters (pass nil for defaults)Returns: Number of bytes downloaded
Example:
file, err := os.Create("downloaded.txt")
if err != nil {
// handle error
}
defer file.Close()
bytesDownloaded, err := client.DownloadFile(ctx, "mycontainer", "myblob.txt", file, nil)Downloads a blob as a stream.
func (c *Client) DownloadStream(ctx context.Context, containerName string, blobName string, o *DownloadStreamOptions) (DownloadStreamResponse, error)Parameters:
ctx: Context for cancellation and deadlinescontainerName: Name of the containerblobName: Name of the blob to downloado: Optional parameters (pass nil for defaults)Example:
import "io"
resp, err := client.DownloadStream(ctx, "mycontainer", "myblob.txt", nil)
if err != nil {
// handle error
}
defer resp.Body.Close()
data, err := io.ReadAll(resp.Body)type CreateContainerOptions struct {
Access *PublicAccessType
Metadata map[string]*string
CPKScopeInfo *CPKScopeInfo
}type DeleteContainerOptions struct {
AccessConditions *AccessConditions
}type DeleteBlobOptions struct {
DeleteSnapshots *DeleteSnapshotsOptionType
AccessConditions *AccessConditions
BlobDeleteType *DeleteType
}type ListContainersOptions struct {
Include ListContainersInclude
Marker *string
MaxResults *int32
Prefix *string
}type ListBlobsFlatOptions struct {
Include ListBlobsInclude
Marker *string
MaxResults *int32
Prefix *string
}type UploadBufferOptions struct {
// Number of blocks to upload in parallel (default: 5)
Concurrency uint16
// Size of each block (default: 4 MB, max: 4 GB)
BlockSize int64
// HTTP headers to set on the blob
HTTPHeaders *blob.HTTPHeaders
// Metadata key-value pairs
Metadata map[string]*string
// Access conditions
AccessConditions *blob.AccessConditions
// Access tier
AccessTier *blob.AccessTier
// Tags
Tags map[string]string
// Client-provided encryption key
CPKInfo *blob.CPKInfo
// Encryption scope
CPKScopeInfo *blob.CPKScopeInfo
// Transfer validation options
TransferValidation TransferValidationType
}type UploadFileOptions struct {
Concurrency uint16
BlockSize int64
HTTPHeaders *blob.HTTPHeaders
Metadata map[string]*string
AccessConditions *blob.AccessConditions
AccessTier *blob.AccessTier
Tags map[string]string
CPKInfo *blob.CPKInfo
CPKScopeInfo *blob.CPKScopeInfo
TransferValidation TransferValidationType
}type UploadStreamOptions struct {
Concurrency uint16
BlockSize int64
HTTPHeaders *blob.HTTPHeaders
Metadata map[string]*string
AccessConditions *blob.AccessConditions
AccessTier *blob.AccessTier
Tags map[string]string
CPKInfo *blob.CPKInfo
CPKScopeInfo *blob.CPKScopeInfo
TransferValidation TransferValidationType
}type DownloadBufferOptions struct {
// Range to download
Range HTTPRange
// Number of parallel download streams (default: 5)
Concurrency uint16
// Size of each chunk to download (default: 4 MB)
BlockSize int64
// Access conditions
AccessConditions *AccessConditions
// Client-provided encryption key
CPKInfo *CPKInfo
// Encryption scope
CPKScopeInfo *CPKScopeInfo
}type DownloadFileOptions struct {
Range HTTPRange
Concurrency uint16
BlockSize int64
AccessConditions *AccessConditions
CPKInfo *CPKInfo
CPKScopeInfo *CPKScopeInfo
}type DownloadStreamOptions struct {
Range HTTPRange
AccessConditions *AccessConditions
CPKInfo *CPKInfo
CPKScopeInfo *CPKScopeInfo
}type CreateContainerResponse struct {
ClientRequestID *string
Date *time.Time
ETag *azcore.ETag
LastModified *time.Time
RequestID *string
Version *string
}type DeleteContainerResponse struct {
ClientRequestID *string
Date *time.Time
RequestID *string
Version *string
}type DeleteBlobResponse struct {
ClientRequestID *string
Date *time.Time
RequestID *string
Version *string
}type UploadBufferResponse struct {
ClientRequestID *string
ContentMD5 []byte
ContentCRC64 []byte
Date *time.Time
ETag *azcore.ETag
EncryptionKeySHA256 *string
EncryptionScope *string
IsServerEncrypted *bool
LastModified *time.Time
RequestID *string
Version *string
VersionID *string
}type UploadFileResponse struct {
ClientRequestID *string
ContentMD5 []byte
ContentCRC64 []byte
Date *time.Time
ETag *azcore.ETag
EncryptionKeySHA256 *string
EncryptionScope *string
IsServerEncrypted *bool
LastModified *time.Time
RequestID *string
Version *string
VersionID *string
}type UploadStreamResponse struct {
ClientRequestID *string
ContentMD5 []byte
ContentCRC64 []byte
Date *time.Time
ETag *azcore.ETag
EncryptionKeySHA256 *string
EncryptionScope *string
IsServerEncrypted *bool
LastModified *time.Time
RequestID *string
Version *string
VersionID *string
}type DownloadStreamResponse struct {
Body io.ReadCloser
// Blob properties
AcceptRanges *string
BlobCommittedBlockCount *int32
BlobContentMD5 []byte
BlobSequenceNumber *int64
BlobType *BlobType
CacheControl *string
ClientRequestID *string
ContentCRC64 []byte
ContentDisposition *string
ContentEncoding *string
ContentLanguage *string
ContentLength *int64
ContentMD5 []byte
ContentRange *string
ContentType *string
CopyCompletionTime *time.Time
CopyID *string
CopyProgress *string
CopySource *string
CopyStatus *CopyStatusType
CopyStatusDescription *string
Date *time.Time
ETag *azcore.ETag
EncryptionKeySHA256 *string
EncryptionScope *string
IsCurrentVersion *bool
IsSealed *bool
IsServerEncrypted *bool
LastModified *time.Time
LeaseDuration *LeaseDurationType
LeaseState *LeaseStateType
LeaseStatus *LeaseStatusType
Metadata map[string]*string
ObjectReplicationPolicyID *string
ObjectReplicationRules []*ObjectReplicationRules
RequestID *string
TagCount *int64
Version *string
VersionID *string
}type ListContainersResponse struct {
ClientRequestID *string
ContainerItems []*ContainerItem
Marker *string
MaxResults *int32
NextMarker *string
Prefix *string
RequestID *string
ServiceEndpoint *string
Version *string
}type ListBlobsFlatResponse struct {
ClientRequestID *string
ContainerName *string
Marker *string
MaxResults *int32
NextMarker *string
Prefix *string
RequestID *string
ServiceEndpoint *string
Segment *BlobFlatListSegment
Version *string
}type SharedKeyCredential = service.SharedKeyCredential
func NewSharedKeyCredential(accountName, accountKey string) (*SharedKeyCredential, error)The SharedKeyCredential is used for shared key authentication with Azure Storage.