or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
golangpkg:golang/github.com/Azure/azure-sdk-for-go/sdk/storage/azblob@v1.6.4

docs

appendblob.mdblob.mdblockblob.mdclient.mdcontainer.mderrors.mdindex.mdlease.mdpageblob.mdsas.mdservice.md
tile.json

tessl/golang-github-com--azure--azure-sdk-for-go--sdk--storage--azblob

tessl install tessl/golang-github-com--azure--azure-sdk-for-go--sdk--storage--azblob@1.6.0

Azure Blob Storage SDK for Go providing comprehensive blob storage operations including uploads, downloads, container management, and advanced features like leases and SAS generation

client.mddocs/

Root Client (azblob.Client)

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.

Client Type

package azblob

type Client struct {
    // contains filtered or unexported fields
}

Constructors

NewClient

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 module
  • options: Client options; pass nil to accept defaults

Example:

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
}

NewClientWithSharedKeyCredential

Creates a client with shared key authentication.

func NewClientWithSharedKeyCredential(serviceURL string, cred *SharedKeyCredential, options *ClientOptions) (*Client, error)

Parameters:

  • serviceURL: The URL of the storage account
  • cred: A SharedKeyCredential created with the storage account name and access key
  • options: Client options; pass nil to accept defaults

Example:

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,
)

NewClientFromConnectionString

Creates a client from a connection string.

func NewClientFromConnectionString(connectionString string, options *ClientOptions) (*Client, error)

Parameters:

  • connectionString: Azure Storage account connection string
  • options: Client options; pass nil to accept defaults

Example:

connectionString := "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=mykey;EndpointSuffix=core.windows.net"
client, err := azblob.NewClientFromConnectionString(connectionString, nil)

NewClientWithNoCredential

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 defaults

Example:

// 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)

Client Options

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
}

Client Methods

URL

Returns the service URL for the client.

func (c *Client) URL() string

ServiceClient

Returns the embedded service client for accessing service-level operations.

func (c *Client) ServiceClient() *service.Client

Container Operations

CreateContainer

Creates 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 deadlines
  • containerName: Name of the container to create
  • o: Optional parameters (pass nil for defaults)

Example:

import "context"

ctx := context.Background()
resp, err := client.CreateContainer(ctx, "mycontainer", nil)
if err != nil {
    // handle error
}

DeleteContainer

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 deadlines
  • containerName: Name of the container to delete
  • o: Optional parameters (pass nil for defaults)

NewListContainersPager

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 listing

Example:

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)
    }
}

Blob Operations

DeleteBlob

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 deadlines
  • containerName: Name of the container containing the blob
  • blobName: Name of the blob to delete
  • o: Optional parameters (pass nil for defaults)

NewListBlobsFlatPager

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 container
  • o: Optional parameters for filtering and controlling the listing

Example:

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)
    }
}

Upload Operations

UploadBuffer

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 deadlines
  • containerName: Name of the container
  • blobName: Name of the blob to create
  • buffer: Byte buffer containing the data to upload
  • o: 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
}

UploadFile

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 deadlines
  • containerName: Name of the container
  • blobName: Name of the blob to create
  • file: Open file handle to upload
  • o: 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)

UploadStream

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 deadlines
  • containerName: Name of the container
  • blobName: Name of the blob to create
  • body: Reader providing the data to upload
  • o: Optional parameters (pass nil for defaults)

Download Operations

DownloadBuffer

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 deadlines
  • containerName: Name of the container
  • blobName: Name of the blob to download
  • buffer: Pre-allocated buffer to receive the data
  • o: 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]

DownloadFile

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 deadlines
  • containerName: Name of the container
  • blobName: Name of the blob to download
  • file: Open file handle to write to
  • o: 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)

DownloadStream

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 deadlines
  • containerName: Name of the container
  • blobName: Name of the blob to download
  • o: 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)

Option Types

CreateContainerOptions

type CreateContainerOptions struct {
    Access   *PublicAccessType
    Metadata map[string]*string
    CPKScopeInfo *CPKScopeInfo
}

DeleteContainerOptions

type DeleteContainerOptions struct {
    AccessConditions *AccessConditions
}

DeleteBlobOptions

type DeleteBlobOptions struct {
    DeleteSnapshots   *DeleteSnapshotsOptionType
    AccessConditions  *AccessConditions
    BlobDeleteType    *DeleteType
}

ListContainersOptions

type ListContainersOptions struct {
    Include    ListContainersInclude
    Marker     *string
    MaxResults *int32
    Prefix     *string
}

ListBlobsFlatOptions

type ListBlobsFlatOptions struct {
    Include    ListBlobsInclude
    Marker     *string
    MaxResults *int32
    Prefix     *string
}

UploadBufferOptions

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
}

UploadFileOptions

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
}

UploadStreamOptions

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
}

DownloadBufferOptions

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
}

DownloadFileOptions

type DownloadFileOptions struct {
    Range            HTTPRange
    Concurrency      uint16
    BlockSize        int64
    AccessConditions *AccessConditions
    CPKInfo          *CPKInfo
    CPKScopeInfo     *CPKScopeInfo
}

DownloadStreamOptions

type DownloadStreamOptions struct {
    Range            HTTPRange
    AccessConditions *AccessConditions
    CPKInfo          *CPKInfo
    CPKScopeInfo     *CPKScopeInfo
}

Response Types

CreateContainerResponse

type CreateContainerResponse struct {
    ClientRequestID *string
    Date            *time.Time
    ETag            *azcore.ETag
    LastModified    *time.Time
    RequestID       *string
    Version         *string
}

DeleteContainerResponse

type DeleteContainerResponse struct {
    ClientRequestID *string
    Date            *time.Time
    RequestID       *string
    Version         *string
}

DeleteBlobResponse

type DeleteBlobResponse struct {
    ClientRequestID *string
    Date            *time.Time
    RequestID       *string
    Version         *string
}

UploadBufferResponse

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
}

UploadFileResponse

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
}

UploadStreamResponse

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
}

DownloadStreamResponse

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
}

ListContainersResponse

type ListContainersResponse struct {
    ClientRequestID  *string
    ContainerItems   []*ContainerItem
    Marker           *string
    MaxResults       *int32
    NextMarker       *string
    Prefix           *string
    RequestID        *string
    ServiceEndpoint  *string
    Version          *string
}

ListBlobsFlatResponse

type ListBlobsFlatResponse struct {
    ClientRequestID  *string
    ContainerName    *string
    Marker           *string
    MaxResults       *int32
    NextMarker       *string
    Prefix           *string
    RequestID        *string
    ServiceEndpoint  *string
    Segment          *BlobFlatListSegment
    Version          *string
}

Shared Key Credential

type SharedKeyCredential = service.SharedKeyCredential

func NewSharedKeyCredential(accountName, accountKey string) (*SharedKeyCredential, error)

The SharedKeyCredential is used for shared key authentication with Azure Storage.