blob

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2024 License: MIT Imports: 17 Imported by: 123

Documentation

Overview

Example (Blob_Client_CreateSnapshot)

This example show how to create a blob, take a snapshot of it, update the base blob, read from the blob snapshot, list blobs with their snapshots, and delete blob snapshots.

package main

import (
	"bytes"
	"context"
	"fmt"
	"log"
	"os"
	"strings"

	"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/container"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	accountName, accountKey := os.Getenv("AZURE_STORAGE_ACCOUNT_NAME"), os.Getenv("AZURE_STORAGE_ACCOUNT_KEY")

	u := fmt.Sprintf("https://%s.blob.core.windows.net/mycontainer", accountName)
	credential, err := blob.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)
	containerClient, err := container.NewClientWithSharedKeyCredential(u, credential, nil)
	handleError(err)

	// Create a blockBlobClient object to a blob in the container.
	baseBlobClient := containerClient.NewBlockBlobClient("Original.txt")

	// Create the original blob:
	_, err = baseBlobClient.Upload(context.TODO(), streaming.NopCloser(streaming.NopCloser(strings.NewReader("Some text"))), nil)
	handleError(err)

	// Create a snapshot of the original blob & save its timestamp:
	createSnapshot, err := baseBlobClient.CreateSnapshot(context.TODO(), nil)
	handleError(err)
	snapshot := *createSnapshot.Snapshot

	// Modify the original blob:
	_, err = baseBlobClient.Upload(context.TODO(), streaming.NopCloser(strings.NewReader("New text")), nil)
	handleError(err)

	// Download the modified blob:
	get, err := baseBlobClient.DownloadStream(context.TODO(), nil)
	handleError(err)
	b := bytes.Buffer{}
	reader := get.Body
	_, err = b.ReadFrom(reader)
	if err != nil {
		return
	}
	err = reader.Close()
	if err != nil {
		return
	}
	fmt.Println(b.String())

	// Show snapshot blob via original blob URI & snapshot time:
	snapshotBlobClient, _ := baseBlobClient.WithSnapshot(snapshot)
	get, err = snapshotBlobClient.DownloadStream(context.TODO(), nil)
	handleError(err)
	b.Reset()
	reader = get.Body
	_, err = b.ReadFrom(reader)
	if err != nil {
		return
	}
	err = reader.Close()
	if err != nil {
		return
	}
	fmt.Println(b.String())

	// FYI: You can get the base blob URL from one of its snapshot by passing "" to WithSnapshot:
	baseBlobClient, _ = snapshotBlobClient.WithSnapshot("")

	// Show all blobs in the container with their snapshots:
	// List the blob(s) in our container; since a container may hold millions of blobs, this is done 1 segment at a time.
	pager := containerClient.NewListBlobsFlatPager(nil)

	for pager.More() {
		resp, err := pager.NextPage(context.TODO())
		if err != nil {
			log.Fatal(err)
		}
		for _, blob := range resp.Segment.BlobItems {
			// Process the blobs returned
			snapTime := "N/A"
			if blob.Snapshot != nil {
				snapTime = *blob.Snapshot
			}
			fmt.Printf("Blob name: %s, Snapshot: %s\n", *blob.Name, snapTime)
		}
	}

	// Promote read-only snapshot to writable base blob:
	_, err = baseBlobClient.StartCopyFromURL(context.TODO(), snapshotBlobClient.URL(), nil)
	handleError(err)

	// When calling Delete on a base blob:
	// DeleteSnapshotsOptionOnly deletes all the base blob's snapshots but not the base blob itself
	// DeleteSnapshotsOptionInclude deletes the base blob & all its snapshots.
	// DeleteSnapshotOptionNone produces an error if the base blob has any snapshots.
	_, err = baseBlobClient.Delete(context.TODO(), &blob.DeleteOptions{DeleteSnapshots: to.Ptr(blob.DeleteSnapshotsOptionTypeInclude)})
	handleError(err)
}
Output:

Example (Blob_Client_SetMetadata)

This example shows how to create a blob with metadata, read blob metadata, and update a blob's read-only properties and metadata.

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"strings"

	"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	accountName, accountKey := os.Getenv("AZURE_STORAGE_ACCOUNT_NAME"), os.Getenv("AZURE_STORAGE_ACCOUNT_KEY")

	// Create a blob client
	u := fmt.Sprintf("https://%s.blob.core.windows.net/mycontainer/ReadMe.txt", accountName)
	credential, err := blob.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)
	blobClient, err := blockblob.NewClientWithSharedKeyCredential(u, credential, nil)
	handleError(err)

	// Create a blob with metadata (string key/value pairs)
	// Metadata key names are always converted to lowercase before being sent to the Storage Service.
	// Always use lowercase letters; especially when querying a map for a metadata key.
	creatingApp, err := os.Executable()
	handleError(err)
	_, err = blobClient.Upload(
		context.TODO(),
		streaming.NopCloser(strings.NewReader("Some text")),
		&blockblob.UploadOptions{Metadata: map[string]*string{"author": to.Ptr("Jeffrey"), "app": to.Ptr(creatingApp)}},
	)
	handleError(err)

	// Query the blob's properties and metadata
	get, err := blobClient.GetProperties(context.TODO(), nil)
	handleError(err)

	// Show some of the blob's read-only properties
	fmt.Printf("BlobType: %s\nETag: %s\nLastModified: %s\n", *get.BlobType, *get.ETag, *get.LastModified)

	// Show the blob's metadata
	if get.Metadata == nil {
		log.Fatal("No metadata returned")
	}

	for k, v := range get.Metadata {
		fmt.Print(k + "=" + *v + "\n")
	}

	// Update the blob's metadata and write it back to the blob
	get.Metadata["editor"] = to.Ptr("Grant")
	_, err = blobClient.SetMetadata(context.TODO(), get.Metadata, nil)
	handleError(err)
}
Output:

Example (Blob_Client_StartCopyFromURL)

This example shows how to copy a source document on the Internet to a blob.

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"time"

	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	accountName, accountKey := os.Getenv("AZURE_STORAGE_ACCOUNT_NAME"), os.Getenv("AZURE_STORAGE_ACCOUNT_KEY")

	// Create a containerClient object to a container where we'll create a blob and its snapshot.
	// Create a blockBlobClient object to a blob in the container.
	blobURL := fmt.Sprintf("https://%s.blob.core.windows.net/mycontainer/CopiedBlob.bin", accountName)
	credential, err := blob.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)
	blobClient, err := blob.NewClientWithSharedKeyCredential(blobURL, credential, nil)
	handleError(err)

	src := "https://cdn2.auth0.com/docs/media/addons/azure_blob.svg"
	startCopy, err := blobClient.StartCopyFromURL(context.TODO(), src, nil)
	handleError(err)

	copyID := *startCopy.CopyID
	copyStatus := *startCopy.CopyStatus
	for copyStatus == blob.CopyStatusTypePending {
		time.Sleep(time.Second * 2)
		getMetadata, err := blobClient.GetProperties(context.TODO(), nil)
		if err != nil {
			log.Fatal(err)
		}
		copyStatus = *getMetadata.CopyStatus
	}
	fmt.Printf("Copy from %s to %s: ID=%s, Status=%s\n", src, blobClient.URL(), copyID, copyStatus)
}
Output:

Example (Blob_HTTPHeaders)

This examples shows how to create a blob with HTTP Headers, how to read, and how to update the blob's HTTP headers.

package main

import (
	"context"
	"fmt"
	"log"
	"os"
	"strings"

	"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blockblob"
)

func handleError(err error) {
	if err != nil {
		log.Fatal(err.Error())
	}
}

func main() {
	accountName, accountKey := os.Getenv("AZURE_STORAGE_ACCOUNT_NAME"), os.Getenv("AZURE_STORAGE_ACCOUNT_KEY")

	// Create a blob client
	u := fmt.Sprintf("https://%s.blob.core.windows.net/mycontainer/ReadMe.txt", accountName)
	credential, err := blob.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)
	blobClient, err := blockblob.NewClientWithSharedKeyCredential(u, credential, nil)
	handleError(err)

	// Create a blob with HTTP headers
	_, err = blobClient.Upload(
		context.TODO(),
		streaming.NopCloser(strings.NewReader("Some text")),
		&blockblob.UploadOptions{HTTPHeaders: &blob.HTTPHeaders{
			BlobContentType:        to.Ptr("text/html; charset=utf-8"),
			BlobContentDisposition: to.Ptr("attachment"),
		}},
	)
	handleError(err)

	// GetMetadata returns the blob's properties, HTTP headers, and metadata
	get, err := blobClient.GetProperties(context.TODO(), nil)
	handleError(err)

	// Show some of the blob's read-only properties
	fmt.Printf("BlobType: %s\nETag: %s\nLastModified: %s\n", *get.BlobType, *get.ETag, *get.LastModified)

	// Shows some of the blob's HTTP Headers
	httpHeaders := blob.ParseHTTPHeaders(get)
	fmt.Println(httpHeaders.BlobContentType, httpHeaders.BlobContentDisposition)

	// Update the blob's HTTP Headers and write them back to the blob
	httpHeaders.BlobContentType = to.Ptr("text/plain")
	_, err = blobClient.SetHTTPHeaders(context.TODO(), httpHeaders, nil)
	handleError(err)
}
Output:

Index

Examples

Constants

View Source
const (
	CountToEnd = 0

	SnapshotTimeFormat = exported.SnapshotTimeFormat

	// DefaultDownloadBlockSize is default block size
	DefaultDownloadBlockSize = int64(4 * 1024 * 1024) // 4MB

	// DefaultConcurrency is the default number of blocks downloaded or uploaded in parallel
	DefaultConcurrency = shared.DefaultConcurrency
)
View Source
const ReadOnClosedBodyMessage = "read on closed response body"

ReadOnClosedBodyMessage of retry reader

Variables

This section is empty.

Functions

This section is empty.

Types

type AbortCopyFromURLOptions

type AbortCopyFromURLOptions struct {
	LeaseAccessConditions *LeaseAccessConditions
}

AbortCopyFromURLOptions contains the optional parameters for the Client.AbortCopyFromURL method.

type AbortCopyFromURLResponse

type AbortCopyFromURLResponse = generated.BlobClientAbortCopyFromURLResponse

AbortCopyFromURLResponse contains the response from method BlobClient.AbortCopyFromURL.

type AccessConditions

type AccessConditions = exported.BlobAccessConditions

AccessConditions identifies blob-specific access conditions which you optionally set.

type AccessTier

type AccessTier = generated.AccessTier

AccessTier defines values for Blob Access Tier.

func PossibleAccessTierValues

func PossibleAccessTierValues() []AccessTier

PossibleAccessTierValues returns the possible values for the AccessTier const type.

type AcquireLeaseResponse

type AcquireLeaseResponse = generated.BlobClientAcquireLeaseResponse

AcquireLeaseResponse contains the response from method BlobClient.AcquireLease.

type ArchiveStatus

type ArchiveStatus = generated.ArchiveStatus

ArchiveStatus defines values for ArchiveStatus.

const (
	ArchiveStatusRehydratePendingToCool ArchiveStatus = generated.ArchiveStatusRehydratePendingToCool
	ArchiveStatusRehydratePendingToHot  ArchiveStatus = generated.ArchiveStatusRehydratePendingToHot
	ArchiveStatusRehydratePendingToCold ArchiveStatus = generated.ArchiveStatusRehydratePendingToCold
)

func PossibleArchiveStatusValues

func PossibleArchiveStatusValues() []ArchiveStatus

PossibleArchiveStatusValues returns the possible values for the ArchiveStatus const type.

type BlobType

type BlobType = generated.BlobType

BlobType defines values for BlobType

const (
	BlobTypeBlockBlob  BlobType = generated.BlobTypeBlockBlob
	BlobTypePageBlob   BlobType = generated.BlobTypePageBlob
	BlobTypeAppendBlob BlobType = generated.BlobTypeAppendBlob
)

func PossibleBlobTypeValues

func PossibleBlobTypeValues() []BlobType

PossibleBlobTypeValues returns the possible values for the BlobType const type.

type BreakLeaseResponse

type BreakLeaseResponse = generated.BlobClientBreakLeaseResponse

BreakLeaseResponse contains the response from method BlobClient.BreakLease.

type CPKInfo added in v1.0.0

type CPKInfo = generated.CPKInfo

CPKInfo contains a group of parameters for client provided encryption key.

type CPKScopeInfo added in v1.0.0

type CPKScopeInfo = generated.CPKScopeInfo

CPKScopeInfo contains a group of parameters for client provided encryption scope.

type ChangeLeaseResponse

type ChangeLeaseResponse = generated.BlobClientChangeLeaseResponse

ChangeLeaseResponse contains the response from method BlobClient.ChangeLease.

type Client

Client represents a URL to an Azure Storage blob; the blob may be a block blob, append blob, or page blob.

func NewClient

func NewClient(blobURL string, cred azcore.TokenCredential, options *ClientOptions) (*Client, error)

NewClient creates an instance of Client with the specified values.

  • blobURL - the URL of the blob e.g. https://<account>.blob.core.windows.net/container/blob.txt
  • cred - an Azure AD credential, typically obtained via the azidentity module
  • options - client options; pass nil to accept the default values

func NewClientFromConnectionString

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

NewClientFromConnectionString creates an instance of Client with the specified values.

  • connectionString - a connection string for the desired storage account
  • containerName - the name of the container within the storage account
  • blobName - the name of the blob within the container
  • options - client options; pass nil to accept the default values

func NewClientWithNoCredential

func NewClientWithNoCredential(blobURL string, options *ClientOptions) (*Client, error)

NewClientWithNoCredential creates an instance of Client with the specified values. This is used to anonymously access a blob or with a shared access signature (SAS) token.

  • blobURL - the URL of the blob e.g. https://<account>.blob.core.windows.net/container/blob.txt?<sas token>
  • options - client options; pass nil to accept the default values

func NewClientWithSharedKeyCredential

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

NewClientWithSharedKeyCredential creates an instance of Client with the specified values.

  • blobURL - the URL of the blob e.g. https://<account>.blob.core.windows.net/container/blob.txt
  • cred - a SharedKeyCredential created with the matching blob's storage account and access key
  • options - client options; pass nil to accept the default values

func (*Client) AbortCopyFromURL

func (b *Client) AbortCopyFromURL(ctx context.Context, copyID string, options *AbortCopyFromURLOptions) (AbortCopyFromURLResponse, error)

AbortCopyFromURL stops a pending copy that was previously started and leaves a destination blob with 0 length and metadata. For more information, see https://docs.microsoft.com/rest/api/storageservices/abort-copy-blob.

func (*Client) CopyFromURL

func (b *Client) CopyFromURL(ctx context.Context, copySource string, options *CopyFromURLOptions) (CopyFromURLResponse, error)

CopyFromURL synchronously copies the data at the source URL to a block blob, with sizes up to 256 MB. For more information, see https://docs.microsoft.com/en-us/rest/api/storageservices/copy-blob-from-url.

func (*Client) CreateSnapshot

func (b *Client) CreateSnapshot(ctx context.Context, options *CreateSnapshotOptions) (CreateSnapshotResponse, error)

CreateSnapshot creates a read-only snapshot of a blob. For more information, see https://docs.microsoft.com/rest/api/storageservices/snapshot-blob.

func (*Client) Delete

func (b *Client) Delete(ctx context.Context, o *DeleteOptions) (DeleteResponse, error)

Delete marks the specified blob or snapshot for deletion. The blob is later deleted during garbage collection. Note that deleting a blob also deletes all its snapshots. For more information, see https://docs.microsoft.com/rest/api/storageservices/delete-blob.

func (*Client) DeleteImmutabilityPolicy added in v0.6.0

func (b *Client) DeleteImmutabilityPolicy(ctx context.Context, options *DeleteImmutabilityPolicyOptions) (DeleteImmutabilityPolicyResponse, error)

DeleteImmutabilityPolicy operation enables users to delete the immutability policy on a blob. https://learn.microsoft.com/en-us/azure/storage/blobs/immutable-storage-overview

func (*Client) DownloadBuffer

func (b *Client) DownloadBuffer(ctx context.Context, buffer []byte, o *DownloadBufferOptions) (int64, error)

DownloadBuffer downloads an Azure blob to a buffer with parallel.

func (*Client) DownloadFile

func (b *Client) DownloadFile(ctx context.Context, file *os.File, o *DownloadFileOptions) (int64, error)

DownloadFile downloads an Azure blob to a local file. The file would be truncated if the size doesn't match.

func (*Client) DownloadStream

DownloadStream reads a range of bytes from a blob. The response also includes the blob's properties and metadata. For more information, see https://docs.microsoft.com/rest/api/storageservices/get-blob.

func (*Client) GetAccountInfo added in v1.1.0

GetAccountInfo provides account level information For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-account-information?tabs=shared-access-signatures.

func (*Client) GetProperties

func (b *Client) GetProperties(ctx context.Context, options *GetPropertiesOptions) (GetPropertiesResponse, error)

GetProperties returns the blob's properties. For more information, see https://docs.microsoft.com/rest/api/storageservices/get-blob-properties.

func (*Client) GetSASURL

func (b *Client) GetSASURL(permissions sas.BlobPermissions, expiry time.Time, o *GetSASURLOptions) (string, error)

GetSASURL is a convenience method for generating a SAS token for the currently pointed at blob. It can only be used if the credential supplied during creation was a SharedKeyCredential.

func (*Client) GetTags

func (b *Client) GetTags(ctx context.Context, options *GetTagsOptions) (GetTagsResponse, error)

GetTags operation enables users to get tags on a blob or specific blob version, or snapshot. https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-tags

func (*Client) SetHTTPHeaders

func (b *Client) SetHTTPHeaders(ctx context.Context, httpHeaders HTTPHeaders, o *SetHTTPHeadersOptions) (SetHTTPHeadersResponse, error)

SetHTTPHeaders changes a blob's HTTP headers. For more information, see https://docs.microsoft.com/rest/api/storageservices/set-blob-properties.

func (*Client) SetImmutabilityPolicy added in v0.6.0

func (b *Client) SetImmutabilityPolicy(ctx context.Context, expiryTime time.Time, options *SetImmutabilityPolicyOptions) (SetImmutabilityPolicyResponse, error)

SetImmutabilityPolicy operation enables users to set the immutability policy on a blob. Mode defaults to "Unlocked". https://learn.microsoft.com/en-us/azure/storage/blobs/immutable-storage-overview

func (*Client) SetLegalHold added in v0.6.0

func (b *Client) SetLegalHold(ctx context.Context, legalHold bool, options *SetLegalHoldOptions) (SetLegalHoldResponse, error)

SetLegalHold operation enables users to set legal hold on a blob. https://learn.microsoft.com/en-us/azure/storage/blobs/immutable-storage-overview

func (*Client) SetMetadata

func (b *Client) SetMetadata(ctx context.Context, metadata map[string]*string, o *SetMetadataOptions) (SetMetadataResponse, error)

SetMetadata changes a blob's metadata. https://docs.microsoft.com/rest/api/storageservices/set-blob-metadata.

func (*Client) SetTags

func (b *Client) SetTags(ctx context.Context, tags map[string]string, options *SetTagsOptions) (SetTagsResponse, error)

SetTags operation enables users to set tags on a blob or specific blob version, but not snapshot. Each call to this operation replaces all existing tags attached to the blob. To remove all tags from the blob, call this operation with no tags set. https://docs.microsoft.com/en-us/rest/api/storageservices/set-blob-tags

func (*Client) SetTier

func (b *Client) SetTier(ctx context.Context, tier AccessTier, o *SetTierOptions) (SetTierResponse, error)

SetTier operation sets the tier on a blob. The operation is allowed on a page blob in a premium storage account and on a block blob in a blob storage account (locally redundant storage only). A premium page blob's tier determines the allowed size, IOPs, and bandwidth of the blob. A block blob's tier determines Hot/Cool/Archive storage type. This operation does not update the blob's ETag. For detailed information about block blob level tiers see https://docs.microsoft.com/en-us/azure/storage/blobs/storage-blob-storage-tiers.

func (*Client) StartCopyFromURL

func (b *Client) StartCopyFromURL(ctx context.Context, copySource string, options *StartCopyFromURLOptions) (StartCopyFromURLResponse, error)

StartCopyFromURL copies the data at the source URL to a blob. For more information, see https://docs.microsoft.com/rest/api/storageservices/copy-blob.

func (*Client) URL

func (b *Client) URL() string

URL returns the URL endpoint used by the Client object.

func (*Client) Undelete

func (b *Client) Undelete(ctx context.Context, o *UndeleteOptions) (UndeleteResponse, error)

Undelete restores the contents and metadata of a soft-deleted blob and any associated soft-deleted snapshots. For more information, see https://docs.microsoft.com/rest/api/storageservices/undelete-blob.

func (*Client) WithSnapshot

func (b *Client) WithSnapshot(snapshot string) (*Client, error)

WithSnapshot creates a new Client object identical to the source but with the specified snapshot timestamp. Pass "" to remove the snapshot returning a URL to the base blob.

func (*Client) WithVersionID

func (b *Client) WithVersionID(versionID string) (*Client, error)

WithVersionID creates a new AppendBlobURL object identical to the source but with the specified version id. Pass "" to remove the versionID returning a URL to the base blob.

type ClientOptions

type ClientOptions base.ClientOptions

ClientOptions contains the optional parameters when creating a Client.

type CopyFromURLOptions

type CopyFromURLOptions struct {
	// Optional. Used to set blob tags in various blob operations.
	BlobTags map[string]string
	// Only Bearer type is supported. Credentials should be a valid OAuth access token to copy source.
	CopySourceAuthorization *string
	// Specifies the date time when the blobs immutability policy is set to expire.
	ImmutabilityPolicyExpiry *time.Time
	// Specifies the immutability policy mode to set on the blob.
	ImmutabilityPolicyMode *ImmutabilityPolicySetting
	// Specified if a legal hold should be set on the blob.
	LegalHold *bool
	// Optional. Specifies a user-defined name-value pair associated with the blob. If no name-value pairs are specified, the
	// operation will copy the metadata from the source blob or file to the destination
	// blob. If one or more name-value pairs are specified, the destination blob is created with the specified metadata, and metadata
	// is not copied from the source blob or file. Note that beginning with
	// version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers. See Naming and Referencing Containers,
	// Blobs, and Metadata for more information.
	Metadata map[string]*string
	// Specify the md5 calculated for the range of bytes that must be read from the copy source.
	SourceContentMD5 []byte
	// Optional. Indicates the tier to be set on the blob.
	Tier *AccessTier

	SourceModifiedAccessConditions *SourceModifiedAccessConditions

	BlobAccessConditions *AccessConditions

	CPKScopeInfo *CPKScopeInfo
}

CopyFromURLOptions contains the optional parameters for the Client.CopyFromURL method.

type CopyFromURLResponse

type CopyFromURLResponse = generated.BlobClientCopyFromURLResponse

CopyFromURLResponse contains the response from method BlobClient.CopyFromURL.

type CopyStatusType

type CopyStatusType = generated.CopyStatusType

CopyStatusType defines values for CopyStatusType

const (
	CopyStatusTypePending CopyStatusType = generated.CopyStatusTypePending
	CopyStatusTypeSuccess CopyStatusType = generated.CopyStatusTypeSuccess
	CopyStatusTypeAborted CopyStatusType = generated.CopyStatusTypeAborted
	CopyStatusTypeFailed  CopyStatusType = generated.CopyStatusTypeFailed
)

func PossibleCopyStatusTypeValues

func PossibleCopyStatusTypeValues() []CopyStatusType

PossibleCopyStatusTypeValues returns the possible values for the CopyStatusType const type.

type CreateSnapshotOptions

type CreateSnapshotOptions struct {
	Metadata         map[string]*string
	AccessConditions *AccessConditions
	CPKInfo          *CPKInfo
	CPKScopeInfo     *CPKScopeInfo
}

CreateSnapshotOptions contains the optional parameters for the Client.CreateSnapshot method.

type CreateSnapshotResponse

type CreateSnapshotResponse = generated.BlobClientCreateSnapshotResponse

CreateSnapshotResponse contains the response from method BlobClient.CreateSnapshot.

type DeleteImmutabilityPolicyOptions added in v0.6.0

type DeleteImmutabilityPolicyOptions struct {
}

DeleteImmutabilityPolicyOptions contains the optional parameters for the Client.DeleteImmutabilityPolicy method.

type DeleteImmutabilityPolicyResponse added in v0.6.0

type DeleteImmutabilityPolicyResponse = generated.BlobClientDeleteImmutabilityPolicyResponse

DeleteImmutabilityPolicyResponse contains the response from method BlobClient.DeleteImmutabilityPolicyResponse.

type DeleteOptions

type DeleteOptions struct {
	// Required if the blob has associated snapshots. Specify one of the following two options: include: Delete the base blob
	// and all of its snapshots. only: Delete only the blob's snapshots and not the blob itself.
	DeleteSnapshots  *DeleteSnapshotsOptionType
	AccessConditions *AccessConditions
	// Setting DeleteType to DeleteTypePermanent will permanently delete soft-delete snapshot and/or version blobs.
	// WARNING: This is a dangerous operation and should not be used unless you know the implications. Please proceed
	// with caution.
	// For more information, see https://docs.microsoft.com/rest/api/storageservices/delete-blob
	BlobDeleteType *DeleteType
}

DeleteOptions contains the optional parameters for the Client.Delete method.

type DeleteResponse

type DeleteResponse = generated.BlobClientDeleteResponse

DeleteResponse contains the response from method BlobClient.Delete.

type DeleteSnapshotsOptionType

type DeleteSnapshotsOptionType = generated.DeleteSnapshotsOptionType

DeleteSnapshotsOptionType defines values for DeleteSnapshotsOptionType

func PossibleDeleteSnapshotsOptionTypeValues

func PossibleDeleteSnapshotsOptionTypeValues() []DeleteSnapshotsOptionType

PossibleDeleteSnapshotsOptionTypeValues returns the possible values for the DeleteSnapshotsOptionType const type.

type DeleteType

type DeleteType = generated.DeleteType

DeleteType defines values for DeleteType.

const (
	DeleteTypeNone      DeleteType = generated.DeleteTypeNone
	DeleteTypePermanent DeleteType = generated.DeleteTypePermanent
)

func PossibleDeleteTypeValues

func PossibleDeleteTypeValues() []DeleteType

PossibleDeleteTypeValues returns the possible values for the DeleteType const type.

type DownloadBufferOptions

type DownloadBufferOptions struct {
	// Range specifies a range of bytes.  The default value is all bytes.
	Range HTTPRange

	// BlockSize specifies the block size to use for each parallel download; the default size is DefaultDownloadBlockSize.
	BlockSize int64

	// Progress is a function that is invoked periodically as bytes are received.
	Progress func(bytesTransferred int64)

	// BlobAccessConditions indicates the access conditions used when making HTTP GET requests against the blob.
	AccessConditions *AccessConditions

	// CPKInfo contains a group of parameters for client provided encryption key.
	CPKInfo *CPKInfo

	// CPKScopeInfo contains a group of parameters for client provided encryption scope.
	CPKScopeInfo *CPKScopeInfo

	// Concurrency indicates the maximum number of blocks to download in parallel (0=default).
	Concurrency uint16

	// RetryReaderOptionsPerBlock is used when downloading each block.
	RetryReaderOptionsPerBlock RetryReaderOptions
}

DownloadBufferOptions contains the optional parameters for the DownloadBuffer method.

type DownloadFileOptions

type DownloadFileOptions struct {
	// Range specifies a range of bytes.  The default value is all bytes.
	Range HTTPRange

	// BlockSize specifies the block size to use for each parallel download; the default size is DefaultDownloadBlockSize.
	BlockSize int64

	// Progress is a function that is invoked periodically as bytes are received.
	Progress func(bytesTransferred int64)

	// BlobAccessConditions indicates the access conditions used when making HTTP GET requests against the blob.
	AccessConditions *AccessConditions

	// ClientProvidedKeyOptions indicates the client provided key by name and/or by value to encrypt/decrypt data.
	CPKInfo      *CPKInfo
	CPKScopeInfo *CPKScopeInfo

	// Concurrency indicates the maximum number of blocks to download in parallel.  The default value is 5.
	Concurrency uint16

	// RetryReaderOptionsPerBlock is used when downloading each block.
	RetryReaderOptionsPerBlock RetryReaderOptions
}

DownloadFileOptions contains the optional parameters for the DownloadFile method.

type DownloadResponse added in v1.0.0

type DownloadResponse = generated.BlobClientDownloadResponse

DownloadResponse contains the response from method BlobClient.Download.

type DownloadStreamOptions

type DownloadStreamOptions struct {
	// When set to true and specified together with the Range, the service returns the MD5 hash for the range, as long as the
	// range is less than or equal to 4 MB in size.
	RangeGetContentMD5 *bool

	// Range specifies a range of bytes.  The default value is all bytes.
	Range HTTPRange

	AccessConditions *AccessConditions
	CPKInfo          *CPKInfo
	CPKScopeInfo     *CPKScopeInfo
}

DownloadStreamOptions contains the optional parameters for the Client.Download method.

type DownloadStreamResponse

type DownloadStreamResponse struct {
	DownloadResponse
	ObjectReplicationRules []ObjectReplicationPolicy
	// contains filtered or unexported fields
}

DownloadStreamResponse contains the response from the DownloadStream method. To read from the stream, read from the Body field, or call the NewRetryReader method.

func (*DownloadStreamResponse) NewRetryReader

func (r *DownloadStreamResponse) NewRetryReader(ctx context.Context, options *RetryReaderOptions) *RetryReader

NewRetryReader constructs new RetryReader stream for reading data. If a connection fails while reading, it will make additional requests to reestablish a connection and continue reading. Pass nil for options to accept the default options. Callers of this method should not access the DownloadStreamResponse.Body field.

type EncryptionAlgorithmType

type EncryptionAlgorithmType = generated.EncryptionAlgorithmType

EncryptionAlgorithmType defines values for EncryptionAlgorithmType.

func PossibleEncryptionAlgorithmTypeValues

func PossibleEncryptionAlgorithmTypeValues() []EncryptionAlgorithmType

PossibleEncryptionAlgorithmTypeValues returns the possible values for the EncryptionAlgorithmType const type.

type GetAccountInfoOptions added in v1.1.0

type GetAccountInfoOptions struct {
}

GetAccountInfoOptions provides set of options for Client.GetAccountInfo

type GetAccountInfoResponse added in v1.1.0

type GetAccountInfoResponse = generated.BlobClientGetAccountInfoResponse

GetAccountInfoResponse contains the response from method BlobClient.GetAccountInfo.

type GetPropertiesOptions

type GetPropertiesOptions struct {
	AccessConditions *AccessConditions
	CPKInfo          *CPKInfo
}

GetPropertiesOptions contains the optional parameters for the Client.GetProperties method

type GetPropertiesResponse

type GetPropertiesResponse = generated.BlobClientGetPropertiesResponse

GetPropertiesResponse contains the response from method BlobClient.GetProperties.

type GetSASURLOptions added in v1.0.0

type GetSASURLOptions struct {
	StartTime *time.Time
}

GetSASURLOptions contains the optional parameters for the Client.GetSASURL method.

type GetTagsOptions

type GetTagsOptions struct {
	// The snapshot parameter is an opaque DateTime value that, when present, specifies the blob snapshot to retrieve.
	Snapshot *string
	// The version id parameter is an opaque DateTime value that, when present, specifies the version of the blob to operate on.
	// It's for service version 2019-10-10 and newer.
	VersionID *string

	BlobAccessConditions *AccessConditions
}

GetTagsOptions contains the optional parameters for the Client.GetTags method.

type GetTagsResponse

type GetTagsResponse = generated.BlobClientGetTagsResponse

GetTagsResponse contains the response from method BlobClient.GetTags.

type HTTPHeaders

type HTTPHeaders = generated.BlobHTTPHeaders

HTTPHeaders contains a group of parameters for the BlobClient.SetHTTPHeaders method.

func ParseHTTPHeaders

func ParseHTTPHeaders(resp GetPropertiesResponse) HTTPHeaders

ParseHTTPHeaders parses GetPropertiesResponse and returns HTTPHeaders.

type HTTPRange

type HTTPRange = exported.HTTPRange

HTTPRange defines a range of bytes within an HTTP resource, starting at offset and ending at offset+count. A zero-value HTTPRange indicates the entire resource. An HTTPRange which has an offset and zero value count indicates from the offset to the resource's end.

type ImmutabilityPolicyMode

type ImmutabilityPolicyMode = generated.ImmutabilityPolicyMode

ImmutabilityPolicyMode defines values for ImmutabilityPolicyMode

func PossibleImmutabilityPolicyModeValues

func PossibleImmutabilityPolicyModeValues() []ImmutabilityPolicyMode

PossibleImmutabilityPolicyModeValues returns the possible values for the ImmutabilityPolicyMode const type.

type ImmutabilityPolicySetting

type ImmutabilityPolicySetting = generated.ImmutabilityPolicySetting

ImmutabilityPolicySetting returns the possible values for the ImmutabilityPolicySetting const type.

func PossibleImmutabilityPolicySettingValues

func PossibleImmutabilityPolicySettingValues() []ImmutabilityPolicySetting

PossibleImmutabilityPolicySettingValues returns the possible values for the ImmutabilityPolicySetting const type.

type LeaseAccessConditions

type LeaseAccessConditions = exported.LeaseAccessConditions

LeaseAccessConditions contains optional parameters to access leased entity.

type ModifiedAccessConditions

type ModifiedAccessConditions = exported.ModifiedAccessConditions

ModifiedAccessConditions contains a group of parameters for specifying access conditions.

type ObjectReplicationPolicy

type ObjectReplicationPolicy struct {
	PolicyID *string
	Rules    *[]ObjectReplicationRules
}

ObjectReplicationPolicy are deserialized attributes.

type ObjectReplicationRules

type ObjectReplicationRules struct {
	RuleID string
	Status string
}

ObjectReplicationRules struct

type QueryFormatType

type QueryFormatType = generated.QueryFormatType

QueryFormatType - The quick query format type.

func PossibleQueryFormatTypeValues

func PossibleQueryFormatTypeValues() []QueryFormatType

PossibleQueryFormatTypeValues returns the possible values for the QueryFormatType const type.

type RehydratePriority

type RehydratePriority = generated.RehydratePriority

RehydratePriority - If an object is in rehydrate pending state then this header is returned with priority of rehydrate. Valid values are High and Standard.

const (
	RehydratePriorityHigh     RehydratePriority = generated.RehydratePriorityHigh
	RehydratePriorityStandard RehydratePriority = generated.RehydratePriorityStandard
)

func PossibleRehydratePriorityValues

func PossibleRehydratePriorityValues() []RehydratePriority

PossibleRehydratePriorityValues returns the possible values for the RehydratePriority const type.

type ReleaseLeaseResponse

type ReleaseLeaseResponse = generated.BlobClientReleaseLeaseResponse

ReleaseLeaseResponse contains the response from method BlobClient.ReleaseLease.

type RenewLeaseResponse

type RenewLeaseResponse = generated.BlobClientRenewLeaseResponse

RenewLeaseResponse contains the response from method BlobClient.RenewLease.

type RetryReader

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

RetryReader attempts to read from response, and if there is a retry-able network error returned during reading, it will retry according to retry reader option through executing user defined action with provided data to get a new response, and continue the overall reading process through reading from the new response. RetryReader implements the io.ReadCloser interface.

func (*RetryReader) Close

func (s *RetryReader) Close() error

Close retry reader

func (*RetryReader) Read

func (s *RetryReader) Read(p []byte) (n int, err error)

Read from retry reader

type RetryReaderOptions

type RetryReaderOptions struct {
	// MaxRetries specifies the maximum number of attempts a failed read will be retried
	// before producing an error.
	// The default value is three.
	MaxRetries int32

	// OnFailedRead, when non-nil, is called after any failure to read. Expected usage is diagnostic logging.
	OnFailedRead func(failureCount int32, lastError error, rnge HTTPRange, willRetry bool)

	// EarlyCloseAsError can be set to true to prevent retries after "read on closed response body". By default,
	// retryReader has the following special behaviour: closing the response body before it is all read is treated as a
	// retryable error. This is to allow callers to force a retry by closing the body from another goroutine (e.g. if the =
	// read is too slow, caller may want to force a retry in the hope that the retry will be quicker).  If
	// TreatEarlyCloseAsError is true, then retryReader's special behaviour is suppressed, and "read on closed body" is instead
	// treated as a fatal (non-retryable) error.
	// Note that setting TreatEarlyCloseAsError only guarantees that Closing will produce a fatal error if the Close happens
	// from the same "thread" (goroutine) as Read.  Concurrent Close calls from other goroutines may instead produce network errors
	// which will be retried.
	// The default value is false.
	EarlyCloseAsError bool
	// contains filtered or unexported fields
}

RetryReaderOptions configures the retry reader's behavior. Zero-value fields will have their specified default values applied during use. This allows for modification of a subset of fields.

type SetHTTPHeadersOptions

type SetHTTPHeadersOptions struct {
	AccessConditions *AccessConditions
}

SetHTTPHeadersOptions contains the optional parameters for the Client.SetHTTPHeaders method.

type SetHTTPHeadersResponse

type SetHTTPHeadersResponse = generated.BlobClientSetHTTPHeadersResponse

SetHTTPHeadersResponse contains the response from method BlobClient.SetHTTPHeaders.

type SetImmutabilityPolicyOptions added in v0.6.0

type SetImmutabilityPolicyOptions struct {
	// Specifies the immutability policy mode to set on the blob. Possible values to set include: "Locked", "Unlocked".
	// "Mutable" can only be returned by service, don't set to "Mutable". If mode is not set - it will default to Unlocked.
	Mode                     *ImmutabilityPolicySetting
	ModifiedAccessConditions *ModifiedAccessConditions
}

SetImmutabilityPolicyOptions contains the parameter for Client.SetImmutabilityPolicy

type SetImmutabilityPolicyResponse added in v0.6.0

type SetImmutabilityPolicyResponse = generated.BlobClientSetImmutabilityPolicyResponse

SetImmutabilityPolicyResponse contains the response from method BlobClient.SetImmutabilityPolicy.

type SetLegalHoldOptions added in v0.6.0

type SetLegalHoldOptions struct {
}

SetLegalHoldOptions contains the optional parameters for the Client.SetLegalHold method.

type SetLegalHoldResponse added in v0.6.0

type SetLegalHoldResponse = generated.BlobClientSetLegalHoldResponse

SetLegalHoldResponse contains the response from method BlobClient.SetLegalHold.

type SetMetadataOptions

type SetMetadataOptions struct {
	AccessConditions *AccessConditions
	CPKInfo          *CPKInfo
	CPKScopeInfo     *CPKScopeInfo
}

SetMetadataOptions provides set of configurations for Set Metadata on blob operation

type SetMetadataResponse

type SetMetadataResponse = generated.BlobClientSetMetadataResponse

SetMetadataResponse contains the response from method BlobClient.SetMetadata.

type SetTagsOptions

type SetTagsOptions struct {
	// The version id parameter is an opaque DateTime value that, when present,
	// specifies the version of the blob to operate on. It's for service version 2019-10-10 and newer.
	VersionID *string
	// Optional header, Specifies the transactional crc64 for the body, to be validated by the service.
	TransactionalContentCRC64 []byte
	// Optional header, Specifies the transactional md5 for the body, to be validated by the service.
	TransactionalContentMD5 []byte

	AccessConditions *AccessConditions
}

SetTagsOptions contains the optional parameters for the Client.SetTags method.

type SetTagsResponse

type SetTagsResponse = generated.BlobClientSetTagsResponse

SetTagsResponse contains the response from method BlobClient.SetTags.

type SetTierOptions

type SetTierOptions struct {
	// Optional: Indicates the priority with which to rehydrate an archived blob.
	RehydratePriority *RehydratePriority

	AccessConditions *AccessConditions
}

SetTierOptions contains the optional parameters for the Client.SetTier method.

type SetTierResponse

type SetTierResponse = generated.BlobClientSetTierResponse

SetTierResponse contains the response from method BlobClient.SetTier.

type SharedKeyCredential

type SharedKeyCredential = exported.SharedKeyCredential

SharedKeyCredential contains an account's name and its primary or secondary key.

func NewSharedKeyCredential

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

NewSharedKeyCredential creates an immutable SharedKeyCredential containing the storage account's name and either its primary or secondary key.

type SourceContentValidationType added in v0.6.0

type SourceContentValidationType interface {
	Apply(generated.SourceContentSetter)
	// contains filtered or unexported methods
}

SourceContentValidationType abstracts the various mechanisms used to validate source content. This interface is not publicly implementable.

type SourceContentValidationTypeCRC64 added in v0.6.0

type SourceContentValidationTypeCRC64 []byte

SourceContentValidationTypeCRC64 is a SourceContentValidationType used to provide a precomputed CRC64.

func (SourceContentValidationTypeCRC64) Apply added in v0.6.0

Apply implements the SourceContentValidationType interface for type SourceContentValidationTypeCRC64.

type SourceContentValidationTypeMD5 added in v0.6.0

type SourceContentValidationTypeMD5 []byte

SourceContentValidationTypeMD5 is a SourceContentValidationType used to provide a precomputed MD5.

func (SourceContentValidationTypeMD5) Apply added in v0.6.0

Apply implements the SourceContentValidationType interface for type SourceContentValidationTypeMD5.

type SourceModifiedAccessConditions

type SourceModifiedAccessConditions = generated.SourceModifiedAccessConditions

SourceModifiedAccessConditions contains a group of parameters for the BlobClient.StartCopyFromURL method.

type StartCopyFromURLOptions

type StartCopyFromURLOptions struct {
	// Specifies the date time when the blobs immutability policy is set to expire.
	ImmutabilityPolicyExpiry *time.Time
	// Specifies the immutability policy mode to set on the blob.
	ImmutabilityPolicyMode *ImmutabilityPolicySetting
	// Specified if a legal hold should be set on the blob.
	LegalHold *bool
	// Optional. Used to set blob tags in various blob operations.
	BlobTags map[string]string
	// Optional. Specifies a user-defined name-value pair associated with the blob. If no name-value pairs are specified, the
	// operation will copy the metadata from the source blob or file to the destination blob. If one or more name-value pairs
	// are specified, the destination blob is created with the specified metadata, and metadata is not copied from the source
	// blob or file. Note that beginning with version 2009-09-19, metadata names must adhere to the naming rules for C# identifiers.
	// See Naming and Referencing Containers, Blobs, and Metadata for more information.
	Metadata map[string]*string
	// Optional: Indicates the priority with which to rehydrate an archived blob.
	RehydratePriority *RehydratePriority
	// Overrides the sealed state of the destination blob. Service version 2019-12-12 and newer.
	SealBlob *bool
	// Optional. Indicates the tier to be set on the blob.
	Tier *AccessTier

	SourceModifiedAccessConditions *SourceModifiedAccessConditions

	AccessConditions *AccessConditions
}

StartCopyFromURLOptions contains the optional parameters for the Client.StartCopyFromURL method.

type StartCopyFromURLResponse

type StartCopyFromURLResponse = generated.BlobClientStartCopyFromURLResponse

StartCopyFromURLResponse contains the response from method BlobClient.StartCopyFromURL.

type Tags

type Tags = generated.BlobTag

Tags represent map of blob index tags

type TransferValidationType added in v0.6.0

type TransferValidationType = exported.TransferValidationType

TransferValidationType abstracts the various mechanisms used to verify a transfer.

func TransferValidationTypeComputeCRC64 added in v0.6.0

func TransferValidationTypeComputeCRC64() TransferValidationType

TransferValidationTypeComputeCRC64 is a TransferValidationType that indicates a CRC64 should be computed during transfer.

type TransferValidationTypeCRC64 added in v0.6.0

type TransferValidationTypeCRC64 = exported.TransferValidationTypeCRC64

TransferValidationTypeCRC64 is a TransferValidationType used to provide a precomputed CRC64.

type TransferValidationTypeMD5 added in v0.6.0

type TransferValidationTypeMD5 = exported.TransferValidationTypeMD5

TransferValidationTypeMD5 is a TransferValidationType used to provide a precomputed MD5.

type URLParts

type URLParts = sas.URLParts

URLParts object represents the components that make up an Azure Storage Container/Blob URL. NOTE: Changing any SAS-related field requires computing a new SAS signature.

func ParseURL

func ParseURL(u string) (URLParts, error)

ParseURL parses a URL initializing URLParts' fields including any SAS-related & snapshot query parameters. Any other query parameters remain in the UnparsedParams field. This method overwrites all fields in the URLParts object.

Example

This example demonstrates splitting a URL into its parts so you can examine and modify the URL in an Azure Storage fluent way.

package main

import (
	"fmt"

	"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob/blob"
)

func main() {
	// Here is an example of a blob snapshot.
	u := "https://myaccount.blob.core.windows.net/mycontainter/ReadMe.txt?" +
		"snapshot=2011-03-09T01:42:34Z&" +
		"sv=2015-02-21&sr=b&st=2111-01-09T01:42:34.936Z&se=2222-03-09T01:42:34.936Z&sp=rw&sip=168.1.5.60-168.1.5.70&" +
		"spr=https,http&si=myIdentifier&ss=bf&srt=s&sig=92836758923659283652983562=="

	// Breaking the URL down into it's parts by conversion to URLParts
	parts, _ := blob.ParseURL(u)

	// The URLParts allows access to individual portions of a Blob URL
	fmt.Printf("Host: %s\nContainerName: %s\nBlobName: %s\nSnapshot: %s\n", parts.Host, parts.ContainerName, parts.BlobName, parts.Snapshot)
	fmt.Printf("Version: %s\nResource: %s\nStartTime: %s\nExpiryTime: %s\nPermissions: %s\n", parts.SAS.Version(), parts.SAS.Resource(), parts.SAS.StartTime(), parts.SAS.ExpiryTime(), parts.SAS.Permissions())
}
Output:

type UndeleteOptions

type UndeleteOptions struct {
}

UndeleteOptions contains the optional parameters for the Client.Undelete method.

type UndeleteResponse

type UndeleteResponse = generated.BlobClientUndeleteResponse

UndeleteResponse contains the response from method BlobClient.Undelete.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL