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 block blob client provides operations specific to block blobs, including uploads, staging blocks, and committing block lists.
import "github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob"type Client struct {
// contains filtered or unexported fields
}func NewClient(blobURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error)
func NewClientWithSharedKeyCredential(blobURL string, cred *blob.SharedKeyCredential, options *ClientOptions) (*Client, error)
func NewClientFromConnectionString(connectionString, containerName, blobName string, options *ClientOptions) (*Client, error)
func NewClientWithNoCredential(blobURL string, options *ClientOptions) (*Client, error)func (c *Client) BlobClient() *blob.Client
func (c *Client) URL() string
func (c *Client) WithSnapshot(snapshot string) (*Client, error)
func (c *Client) WithVersionID(versionID string) (*Client, error)Simple upload for smaller blobs (up to 256 MB).
func (c *Client) Upload(ctx context.Context, body io.ReadSeekCloser, options *UploadOptions) (UploadResponse, error)Options:
type UploadOptions struct {
HTTPHeaders *blob.HTTPHeaders
Metadata map[string]*string
Tags map[string]string
AccessConditions *blob.AccessConditions
AccessTier *blob.AccessTier
CPKInfo *blob.CPKInfo
CPKScopeInfo *blob.CPKScopeInfo
TransferValidation blob.TransferValidationType
}Upload from byte buffer with automatic block management.
func (c *Client) UploadBuffer(ctx context.Context, buffer []byte, o *UploadBufferOptions) (UploadBufferResponse, error)Options:
type UploadBufferOptions struct {
Concurrency uint16
BlockSize int64
HTTPHeaders *blob.HTTPHeaders
Metadata map[string]*string
Tags map[string]string
AccessConditions *blob.AccessConditions
AccessTier *blob.AccessTier
CPKInfo *blob.CPKInfo
CPKScopeInfo *blob.CPKScopeInfo
TransferValidation blob.TransferValidationType
}Upload from file with automatic block management.
func (c *Client) UploadFile(ctx context.Context, file *os.File, o *UploadFileOptions) (UploadFileResponse, error)Upload from stream with automatic block management.
func (c *Client) UploadStream(ctx context.Context, body io.Reader, o *UploadStreamOptions) (UploadStreamResponse, error)Upload directly from a URL source.
func (c *Client) UploadBlobFromURL(ctx context.Context, copySource string, options *UploadBlobFromURLOptions) (UploadBlobFromURLResponse, error)Stages a block with a specified block ID.
func (c *Client) StageBlock(ctx context.Context, base64BlockID string, body io.ReadSeekCloser, options *StageBlockOptions) (StageBlockResponse, error)Options:
type StageBlockOptions struct {
CPKInfo *blob.CPKInfo
CPKScopeInfo *blob.CPKScopeInfo
LeaseAccessConditions *blob.LeaseAccessConditions
TransferValidation blob.TransferValidationType
}Example:
import "encoding/base64"
// Create block ID
blockID := base64.StdEncoding.EncodeToString([]byte("block-001"))
// Stage block
data := bytes.NewReader([]byte("block data"))
_, err := blockBlobClient.StageBlock(ctx, blockID, streaming.NopCloser(data), nil)Stages a block from a URL source.
func (c *Client) StageBlockFromURL(ctx context.Context, base64BlockID string, sourceURL string, options *StageBlockFromURLOptions) (StageBlockFromURLResponse, error)Options:
type StageBlockFromURLOptions struct {
SourceRange *blob.HTTPRange
SourceContentMD5 []byte
SourceContentCRC64 []byte
CPKInfo *blob.CPKInfo
CPKScopeInfo *blob.CPKScopeInfo
LeaseAccessConditions *blob.LeaseAccessConditions
SourceModifiedAccessConditions *blob.SourceModifiedAccessConditions
}Commits a list of staged blocks to create or update a blob.
func (c *Client) CommitBlockList(ctx context.Context, base64BlockIDs []string, options *CommitBlockListOptions) (CommitBlockListResponse, error)Options:
type CommitBlockListOptions struct {
HTTPHeaders *blob.HTTPHeaders
Metadata map[string]*string
Tags map[string]string
AccessConditions *blob.AccessConditions
AccessTier *blob.AccessTier
CPKInfo *blob.CPKInfo
CPKScopeInfo *blob.CPKScopeInfo
TransferValidation blob.TransferValidationType
}Example:
blockIDs := []string{
base64.StdEncoding.EncodeToString([]byte("block-001")),
base64.StdEncoding.EncodeToString([]byte("block-002")),
base64.StdEncoding.EncodeToString([]byte("block-003")),
}
_, err := blockBlobClient.CommitBlockList(ctx, blockIDs, nil)Retrieves the list of committed and/or uncommitted blocks.
func (c *Client) GetBlockList(ctx context.Context, listType BlockListType, options *GetBlockListOptions) (GetBlockListResponse, error)Options:
type GetBlockListOptions struct {
Snapshot *string
AccessConditions *blob.AccessConditions
}Sets blob expiry time (hierarchical namespace only).
func (c *Client) SetExpiry(ctx context.Context, expiryType ExpiryType, o *SetExpiryOptions) (SetExpiryResponse, error)Options:
type SetExpiryOptions struct {
ExpiresOn *time.Time
}const (
MaxUploadBlobBytes int64 = 256 * 1024 * 1024 // 256 MB
MaxStageBlockBytes int64 = 4 * 1024 * 1024 * 1024 // 4 GB
MaxBlocks int = 50000
CountToEnd int64 = 0 // Used in HTTPRange to read to end of blob
)type BlockListType string
const (
BlockListTypeCommitted BlockListType = "committed"
BlockListTypeUncommitted BlockListType = "uncommitted"
BlockListTypeAll BlockListType = "all"
)
func PossibleBlockListTypeValues() []BlockListTypetype BlobCopySourceTags string
const (
BlobCopySourceTagsCopy BlobCopySourceTags = "COPY"
BlobCopySourceTagsReplace BlobCopySourceTags = "REPLACE"
)
func PossibleBlobCopySourceTagsValues() []BlobCopySourceTagstype ExpiryType string
const (
ExpiryTypeAbsolute ExpiryType = "Absolute"
ExpiryTypeNever ExpiryType = "NeverExpire"
ExpiryTypeRelativeToCreation ExpiryType = "RelativeToCreation"
ExpiryTypeRelativeToNow ExpiryType = "RelativeToNow"
)
func PossibleExpiryTypeValues() []ExpiryTypetype Block struct {
Name *string
Size *int64
}type BlockList struct {
CommittedBlocks []*Block
UncommittedBlocks []*Block
}type ClientOptions struct {
Telemetry policy.TelemetryOptions
Transport policy.Transporter
Retry policy.RetryOptions
PerCallPolicies []policy.Policy
PerRetryPolicies []policy.Policy
InsecureAllowCredentialWithHTTP bool
DisableRPRegistration bool
}