file

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 License: MIT Imports: 24 Imported by: 8

Documentation

Overview

Example (Client_NewClient_CreateShare_CreateDir_CreateFile)
package main

import (
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
	"log"
	"os"
)

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

func main() {
	accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME")
	if !ok {
		panic("AZURE_STORAGE_ACCOUNT_NAME could not be found")
	}
	accountKey, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_KEY")
	if !ok {
		panic("AZURE_STORAGE_ACCOUNT_KEY could not be found")
	}

	serviceURL := fmt.Sprintf("https://%s.file.core.windows.net/", accountName)
	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	client, err := service.NewClientWithSharedKeyCredential(serviceURL, cred, nil)
	handleError(err)

	shareClient := client.NewShareClient("testShare")
	fmt.Println(shareClient.URL())

	dirClient := shareClient.NewDirectoryClient("testDir")
	fmt.Println(dirClient.URL())

	fileClient := dirClient.NewFileClient("testFile")
	fmt.Println(fileClient.URL())

}
Output:

Example (FileClient_CopyFileUsingDestinationProperties)
package main

import (
	"bytes"
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"io"
	"log"
	"os"
	"strings"
	"time"
)

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

const random64BString string = "2SDgZj6RkKYzJpu04sweQek4uWHO8ndPnYlZ0tnFS61hjnFZ5IkvIGGY44eKABov"

func generateData(sizeInBytes int) (io.ReadSeekCloser, []byte) {
	data := make([]byte, sizeInBytes)
	_len := len(random64BString)
	if sizeInBytes > _len {
		count := sizeInBytes / _len
		if sizeInBytes%_len != 0 {
			count = count + 1
		}
		copy(data[:], strings.Repeat(random64BString, count))
	} else {
		copy(data[:], random64BString)
	}
	return streaming.NopCloser(bytes.NewReader(data)), data
}

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	srcFileName := "testFile"
	dstFileName := "testFile2"
	fileSize := int64(5)

	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	srcFileClient := shareClient.NewRootDirectoryClient().NewFileClient(srcFileName)
	_, err = srcFileClient.Create(context.Background(), fileSize, nil)
	handleError(err)

	dstFileClient := shareClient.NewRootDirectoryClient().NewFileClient(dstFileName)

	contentR, _ := generateData(int(fileSize))

	_, err = srcFileClient.UploadRange(context.Background(), 0, contentR, nil)
	handleError(err)

	destCreationTime := time.Now().Add(5 * time.Minute)
	destLastWriteTIme := time.Now().Add(6 * time.Minute)
	destChangeTime := time.Now().Add(7 * time.Minute)
	_, err = dstFileClient.StartCopyFromURL(context.Background(), srcFileClient.URL(), &file.StartCopyFromURLOptions{
		CopyFileSMBInfo: &file.CopyFileSMBInfo{
			CreationTime:  file.DestinationCopyFileCreationTime(destCreationTime),
			LastWriteTime: file.DestinationCopyFileLastWriteTime(destLastWriteTIme),
			ChangeTime:    file.DestinationCopyFileChangeTime(destChangeTime),
			Attributes:    file.DestinationCopyFileAttributes{ReadOnly: true},
		},
	})
	handleError(err)
	fmt.Println("File copied")
}
Output:

Example (FileClient_CopyFileUsingSourceProperties)
package main

import (
	"bytes"
	"context"
	"fmt"
	"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/azfile/file"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"io"
	"log"
	"os"
	"strings"
)

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

const random64BString string = "2SDgZj6RkKYzJpu04sweQek4uWHO8ndPnYlZ0tnFS61hjnFZ5IkvIGGY44eKABov"

func generateData(sizeInBytes int) (io.ReadSeekCloser, []byte) {
	data := make([]byte, sizeInBytes)
	_len := len(random64BString)
	if sizeInBytes > _len {
		count := sizeInBytes / _len
		if sizeInBytes%_len != 0 {
			count = count + 1
		}
		copy(data[:], strings.Repeat(random64BString, count))
	} else {
		copy(data[:], random64BString)
	}
	return streaming.NopCloser(bytes.NewReader(data)), data
}

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	srcFileName := "testFile"
	dstFileName := "testFile2"
	fileSize := int64(5)

	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	srcFileClient := shareClient.NewRootDirectoryClient().NewFileClient(srcFileName)
	_, err = srcFileClient.Create(context.Background(), fileSize, nil)
	handleError(err)

	dstFileClient := shareClient.NewRootDirectoryClient().NewFileClient(dstFileName)

	contentR, _ := generateData(int(fileSize))

	_, err = srcFileClient.UploadRange(context.Background(), 0, contentR, nil)
	handleError(err)

	_, err = dstFileClient.StartCopyFromURL(context.Background(), srcFileClient.URL(), &file.StartCopyFromURLOptions{
		CopyFileSMBInfo: &file.CopyFileSMBInfo{
			CreationTime:       file.SourceCopyFileCreationTime{},
			LastWriteTime:      file.SourceCopyFileLastWriteTime{},
			ChangeTime:         file.SourceCopyFileChangeTime{},
			Attributes:         file.SourceCopyFileAttributes{},
			PermissionCopyMode: to.Ptr(file.PermissionCopyModeTypeSource),
		},
	})
	handleError(err)
	fmt.Println("File copied")
}
Output:

Example (FileClient_CreateAndDelete)
package main

import (
	"context"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"log"
	"os"
)

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

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	fileName := "testFile"
	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	fileClient := shareClient.NewRootDirectoryClient().NewFileClient(fileName)
	_, err = fileClient.Create(context.Background(), 5, nil)
	handleError(err)

	_, err = fileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (FileClient_DownloadBuffer)
package main

import (
	"context"
	"crypto/rand"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"log"
	"os"
)

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

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	srcFileName := "testFile"
	fileSize := int64(5)

	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	srcFileClient := shareClient.NewRootDirectoryClient().NewFileClient(srcFileName)
	_, err = srcFileClient.Create(context.Background(), fileSize, nil)
	handleError(err)

	content := make([]byte, fileSize)
	_, err = rand.Read(content)
	handleError(err)

	err = srcFileClient.UploadBuffer(context.Background(), content, nil)
	handleError(err)

	destBuffer := make([]byte, fileSize)
	_, err = srcFileClient.DownloadBuffer(context.Background(), destBuffer, nil)
	handleError(err)

	_, err = srcFileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (FileClient_DownloadFile)
package main

import (
	"context"
	"crypto/rand"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"log"
	"os"
)

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

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	srcFileName := "testFile"
	fileSize := int64(5)

	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	srcFileClient := shareClient.NewRootDirectoryClient().NewFileClient(srcFileName)
	_, err = srcFileClient.Create(context.Background(), fileSize, nil)
	handleError(err)

	content := make([]byte, fileSize)
	_, err = rand.Read(content)
	handleError(err)

	err = srcFileClient.UploadBuffer(context.Background(), content, nil)
	handleError(err)

	destFileName := "file.bin"
	destFile, err := os.Create(destFileName)
	handleError(err)
	defer func(name string) {
		err = os.Remove(name)
		handleError(err)
	}(destFileName)
	defer func(destFile *os.File) {
		err = destFile.Close()
		handleError(err)
	}(destFile)

	_, err = srcFileClient.DownloadFile(context.Background(), destFile, nil)
	handleError(err)

	_, err = srcFileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (FileClient_DownloadStream)
package main

import (
	"bytes"
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"io"
	"log"
	"os"
	"strings"
)

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

const random64BString string = "2SDgZj6RkKYzJpu04sweQek4uWHO8ndPnYlZ0tnFS61hjnFZ5IkvIGGY44eKABov"

func generateData(sizeInBytes int) (io.ReadSeekCloser, []byte) {
	data := make([]byte, sizeInBytes)
	_len := len(random64BString)
	if sizeInBytes > _len {
		count := sizeInBytes / _len
		if sizeInBytes%_len != 0 {
			count = count + 1
		}
		copy(data[:], strings.Repeat(random64BString, count))
	} else {
		copy(data[:], random64BString)
	}
	return streaming.NopCloser(bytes.NewReader(data)), data
}

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	srcFileName := "testFile"
	fileSize := int64(5)

	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	srcFileClient := shareClient.NewRootDirectoryClient().NewFileClient(srcFileName)
	_, err = srcFileClient.Create(context.Background(), fileSize, nil)
	handleError(err)

	contentR, _ := generateData(int(fileSize))

	_, err = srcFileClient.UploadRange(context.Background(), 0, contentR, nil)
	handleError(err)

	// validate data copied
	resp, err := srcFileClient.DownloadStream(context.Background(), &file.DownloadStreamOptions{
		Range: file.HTTPRange{Offset: 0, Count: fileSize},
	})
	handleError(err)

	content1, err := io.ReadAll(resp.Body)
	handleError(err)
	fmt.Println(content1)

	_, err = srcFileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (FileClient_GetProperties)
package main

import (
	"context"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"log"
	"os"
)

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

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	fileName := "testFile"
	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	fileClient := shareClient.NewRootDirectoryClient().NewFileClient(fileName)
	_, err = fileClient.Create(context.Background(), 5, nil)
	handleError(err)

	_, err = fileClient.GetProperties(context.Background(), nil)
	handleError(err)

	_, err = fileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)

}
Output:

Example (FileClient_OAuth)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
	"log"
	"os"
)

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

func main() {
	accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME")
	if !ok {
		panic("AZURE_STORAGE_ACCOUNT_NAME could not be found")
	}

	cred, err := azidentity.NewDefaultAzureCredential(nil)
	handleError(err)

	shareName := "testShare"
	fileName := "testFile"
	fileURL := "https://" + accountName + ".file.core.windows.net/" + shareName + "/" + fileName

	fileClient, err := file.NewClient(fileURL, cred, &file.ClientOptions{FileRequestIntent: to.Ptr(file.ShareTokenIntentBackup)})
	handleError(err)

	_, err = fileClient.Create(context.TODO(), 2048, nil)
	handleError(err)
	fmt.Println("File created")

	_, err = fileClient.GetProperties(context.TODO(), nil)
	handleError(err)
	fmt.Println("File properties retrieved")

	_, err = fileClient.Delete(context.TODO(), nil)
	handleError(err)
	fmt.Println("File deleted")
}
Output:

Example (FileClient_Rename)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
	"log"
	"os"
)

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

func main() {
	accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME")
	if !ok {
		panic("AZURE_STORAGE_ACCOUNT_NAME could not be found")
	}

	cred, err := azidentity.NewDefaultAzureCredential(nil)
	handleError(err)

	shareName := "testShare"
	srcFileName := "testFile"
	destFileName := "newFile"
	srcFileURL := "https://" + accountName + ".file.core.windows.net/" + shareName + "/" + srcFileName

	srcFileClient, err := file.NewClient(srcFileURL, cred, &file.ClientOptions{FileRequestIntent: to.Ptr(file.ShareTokenIntentBackup)})
	handleError(err)

	_, err = srcFileClient.Rename(context.TODO(), destFileName, nil)
	handleError(err)
	fmt.Println("File renamed")
}
Output:

Example (FileClient_Resize)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"log"
	"os"
)

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

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	srcFileName := "testFile"
	fileSize := int64(5)

	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	srcFileClient := shareClient.NewRootDirectoryClient().NewFileClient(srcFileName)
	_, err = srcFileClient.Create(context.Background(), fileSize, nil)
	handleError(err)

	resp1, err := srcFileClient.GetProperties(context.Background(), nil)
	handleError(err)
	fmt.Println(*resp1.ContentLength)

	_, err = srcFileClient.Resize(context.Background(), 6, nil)
	handleError(err)

	resp1, err = srcFileClient.GetProperties(context.Background(), nil)
	handleError(err)
	fmt.Println(*resp1.ContentLength)

	_, err = srcFileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (FileClient_SetAndGetMetadata)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"log"
	"os"
)

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

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	fileName := "testFile"
	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	fileClient := shareClient.NewRootDirectoryClient().NewFileClient(fileName)
	_, err = fileClient.Create(context.Background(), 5, nil)
	handleError(err)

	opts := file.SetMetadataOptions{Metadata: map[string]*string{"hello": to.Ptr("world")}}
	_, err = fileClient.SetMetadata(context.Background(), &opts)
	handleError(err)

	get, err := fileClient.GetProperties(context.Background(), nil)
	handleError(err)

	if get.Metadata == nil {
		log.Fatal("No metadata returned")
	}
	for k, v := range get.Metadata {
		fmt.Print(k + "=" + *v + "\n")
	}

	_, err = fileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (FileClient_StartCopyFromURL)
package main

import (
	"bytes"
	"context"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"io"
	"log"
	"os"
	"strings"
)

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

const random64BString string = "2SDgZj6RkKYzJpu04sweQek4uWHO8ndPnYlZ0tnFS61hjnFZ5IkvIGGY44eKABov"

func generateData(sizeInBytes int) (io.ReadSeekCloser, []byte) {
	data := make([]byte, sizeInBytes)
	_len := len(random64BString)
	if sizeInBytes > _len {
		count := sizeInBytes / _len
		if sizeInBytes%_len != 0 {
			count = count + 1
		}
		copy(data[:], strings.Repeat(random64BString, count))
	} else {
		copy(data[:], random64BString)
	}
	return streaming.NopCloser(bytes.NewReader(data)), data
}

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	srcFileName := "testFile"
	dstFileName := "testFile2"
	fileSize := int64(5)

	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	srcFileClient := shareClient.NewRootDirectoryClient().NewFileClient(srcFileName)
	_, err = srcFileClient.Create(context.Background(), fileSize, nil)
	handleError(err)

	dstFileClient := shareClient.NewRootDirectoryClient().NewFileClient(dstFileName)

	contentR, _ := generateData(int(fileSize))

	_, err = srcFileClient.UploadRange(context.Background(), 0, contentR, nil)
	handleError(err)

	// you can also use AbortCopy to abort copying
	_, err = dstFileClient.StartCopyFromURL(context.Background(), srcFileClient.URL(), nil)
	handleError(err)

	_, err = srcFileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = dstFileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (FileClient_TrailingDot)
package main

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
	"log"
	"os"
)

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

func main() {
	accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME")
	if !ok {
		panic("AZURE_STORAGE_ACCOUNT_NAME could not be found")
	}

	cred, err := azidentity.NewDefaultAzureCredential(nil)
	handleError(err)

	shareName := "testShare"
	fileName := "testFile.." // file name with trailing dot
	fileURL := "https://" + accountName + ".file.core.windows.net/" + shareName + "/" + fileName

	fileClient, err := file.NewClient(fileURL, cred, &file.ClientOptions{
		FileRequestIntent: to.Ptr(file.ShareTokenIntentBackup),
		AllowTrailingDot:  to.Ptr(true),
	})
	handleError(err)

	_, err = fileClient.Create(context.TODO(), 2048, nil)
	handleError(err)
	fmt.Println("File created")

	_, err = fileClient.GetProperties(context.TODO(), nil)
	handleError(err)
	fmt.Println("File properties retrieved")

	_, err = fileClient.Delete(context.TODO(), nil)
	handleError(err)
	fmt.Println("File deleted")
}
Output:

Example (FileClient_UploadAndClearRange)
package main

import (
	"bytes"
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"io"
	"log"
	"os"
	"strings"
)

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

const random64BString string = "2SDgZj6RkKYzJpu04sweQek4uWHO8ndPnYlZ0tnFS61hjnFZ5IkvIGGY44eKABov"

func generateData(sizeInBytes int) (io.ReadSeekCloser, []byte) {
	data := make([]byte, sizeInBytes)
	_len := len(random64BString)
	if sizeInBytes > _len {
		count := sizeInBytes / _len
		if sizeInBytes%_len != 0 {
			count = count + 1
		}
		copy(data[:], strings.Repeat(random64BString, count))
	} else {
		copy(data[:], random64BString)
	}
	return streaming.NopCloser(bytes.NewReader(data)), data
}

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	fileName := "testFile"
	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	fileClient := shareClient.NewRootDirectoryClient().NewFileClient(fileName)
	_, err = fileClient.Create(context.Background(), 5, nil)
	handleError(err)

	contentR, _ := generateData(5)

	_, err = fileClient.UploadRange(context.Background(), 0, contentR, nil)
	handleError(err)

	rangeList, err := fileClient.GetRangeList(context.Background(), nil)
	handleError(err)
	fmt.Println(rangeList.Ranges)

	_, err = fileClient.ClearRange(context.Background(), file.HTTPRange{Offset: 0, Count: int64(5)}, nil)
	handleError(err)

	rangeList2, err := fileClient.GetRangeList(context.Background(), nil)
	handleError(err)

	fmt.Println(rangeList2.Ranges, 0)
	_, err = fileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (FileClient_UploadBuffer)
package main

import (
	"context"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"log"
	"os"
)

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

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	fileName := "testFile"
	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	fileClient := shareClient.NewRootDirectoryClient().NewFileClient(fileName)
	_, err = fileClient.Create(context.Background(), 5, nil)
	handleError(err)

	data := []byte{'h', 'e', 'l', 'l', 'o'}
	err = fileClient.UploadBuffer(context.Background(), data, nil)
	handleError(err)

	_, err = fileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (FileClient_UploadFile)
package main

import (
	"bytes"
	"context"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"io"
	"log"
	"os"
	"strings"
)

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

const random64BString string = "2SDgZj6RkKYzJpu04sweQek4uWHO8ndPnYlZ0tnFS61hjnFZ5IkvIGGY44eKABov"

func generateData(sizeInBytes int) (io.ReadSeekCloser, []byte) {
	data := make([]byte, sizeInBytes)
	_len := len(random64BString)
	if sizeInBytes > _len {
		count := sizeInBytes / _len
		if sizeInBytes%_len != 0 {
			count = count + 1
		}
		copy(data[:], strings.Repeat(random64BString, count))
	} else {
		copy(data[:], random64BString)
	}
	return streaming.NopCloser(bytes.NewReader(data)), data
}

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	srcFileName := "testFile"
	fileSize := int64(5)

	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	srcFileClient := shareClient.NewRootDirectoryClient().NewFileClient(srcFileName)
	_, err = srcFileClient.Create(context.Background(), fileSize, nil)
	handleError(err)

	_, content := generateData(int(fileSize))
	err = os.WriteFile(srcFileName, content, 0644)
	handleError(err)
	defer func() {
		err = os.Remove(srcFileName)
		handleError(err)
	}()
	fh, err := os.Open(srcFileName)
	handleError(err)
	defer func(fh *os.File) {
		err := fh.Close()
		handleError(err)
	}(fh)

	err = srcFileClient.UploadFile(context.Background(), fh, nil)

	destFileName := "file.bin"
	destFile, err := os.Create(destFileName)
	handleError(err)
	defer func(name string) {
		err = os.Remove(name)
		handleError(err)
	}(destFileName)
	defer func(destFile *os.File) {
		err = destFile.Close()
		handleError(err)
	}(destFile)

	_, err = srcFileClient.DownloadFile(context.Background(), destFile, nil)
	handleError(err)

	_, err = srcFileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (FileClient_UploadRangeFromURL)
package main

import (
	"bytes"
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/sas"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/service"
	"io"
	"log"
	"os"
	"strings"
	"time"
)

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

const random64BString string = "2SDgZj6RkKYzJpu04sweQek4uWHO8ndPnYlZ0tnFS61hjnFZ5IkvIGGY44eKABov"

func generateData(sizeInBytes int) (io.ReadSeekCloser, []byte) {
	data := make([]byte, sizeInBytes)
	_len := len(random64BString)
	if sizeInBytes > _len {
		count := sizeInBytes / _len
		if sizeInBytes%_len != 0 {
			count = count + 1
		}
		copy(data[:], strings.Repeat(random64BString, count))
	} else {
		copy(data[:], random64BString)
	}
	return streaming.NopCloser(bytes.NewReader(data)), data
}

func main() {
	accountName, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_NAME")
	if !ok {
		panic("AZURE_STORAGE_ACCOUNT_NAME could not be found")
	}
	accountKey, ok := os.LookupEnv("AZURE_STORAGE_ACCOUNT_KEY")
	if !ok {
		panic("AZURE_STORAGE_ACCOUNT_KEY could not be found")
	}

	serviceURL := fmt.Sprintf("https://%s.file.core.windows.net/", accountName)
	cred, err := service.NewSharedKeyCredential(accountName, accountKey)
	handleError(err)

	client, err := service.NewClientWithSharedKeyCredential(serviceURL, cred, nil)
	handleError(err)

	shareName := "testShare"
	srcFileName := "testFile"
	dstFileName := "testFile2"
	fileSize := int64(5)

	shareClient := client.NewShareClient(shareName)
	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	srcFileClient := shareClient.NewRootDirectoryClient().NewFileClient(srcFileName)
	_, err = srcFileClient.Create(context.Background(), fileSize, nil)
	handleError(err)

	contentR, _ := generateData(int(fileSize))

	_, err = srcFileClient.UploadRange(context.Background(), 0, contentR, nil)
	handleError(err)

	contentSize := 1024 * 8 // 8KB
	content := make([]byte, contentSize)
	body := bytes.NewReader(content)
	rsc := streaming.NopCloser(body)

	_, err = srcFileClient.UploadRange(context.Background(), 0, rsc, nil)
	handleError(err)

	perms := sas.FilePermissions{Read: true, Write: true}
	sasQueryParams, err := sas.SignatureValues{
		Protocol:    sas.ProtocolHTTPS,                    // Users MUST use HTTPS (not HTTP)
		ExpiryTime:  time.Now().UTC().Add(48 * time.Hour), // 48-hours before expiration
		ShareName:   shareName,
		FilePath:    srcFileName,
		Permissions: perms.String(),
	}.SignWithSharedKey(cred)
	handleError(err)

	srcFileSAS := srcFileClient.URL() + "?" + sasQueryParams.Encode()

	destFClient := shareClient.NewRootDirectoryClient().NewFileClient(dstFileName)
	_, err = destFClient.Create(context.Background(), fileSize, nil)
	handleError(err)

	_, err = destFClient.UploadRangeFromURL(context.Background(), srcFileSAS, 0, 0, int64(contentSize), nil)
	handleError(err)
}
Output:

Example (FileClient_UploadStream)
package main

import (
	"context"
	"github.com/Azure/azure-sdk-for-go/sdk/azcore/streaming"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"log"
	"os"
	"strings"
)

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

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	fileName := "testFile"
	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	fileClient := shareClient.NewRootDirectoryClient().NewFileClient(fileName)
	_, err = fileClient.Create(context.Background(), 5, nil)
	handleError(err)

	err = fileClient.UploadStream(
		context.TODO(),
		streaming.NopCloser(strings.NewReader("Some text")),
		nil,
	)
	handleError(err)

	_, err = fileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (File_ClientGetSASURL)
package main

import (
	"context"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/sas"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/share"
	"log"
	"os"
	"time"
)

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

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	srcFileName := "testFile"
	fileSize := int64(5)

	shareClient, err := share.NewClientFromConnectionString(connectionString, shareName, nil)
	handleError(err)

	_, err = shareClient.Create(context.Background(), nil)
	handleError(err)

	srcFileClient := shareClient.NewRootDirectoryClient().NewFileClient(srcFileName)
	_, err = srcFileClient.Create(context.Background(), fileSize, nil)
	handleError(err)

	permission := sas.FilePermissions{Read: true}
	start := time.Now()
	expiry := start.AddDate(1, 0, 0)
	options := file.GetSASURLOptions{StartTime: &start}
	sasURL, err := srcFileClient.GetSASURL(permission, expiry, &options)
	handleError(err)
	_ = sasURL

	_, err = srcFileClient.Delete(context.Background(), nil)
	handleError(err)

	_, err = shareClient.Delete(context.Background(), nil)
	handleError(err)
}
Output:

Example (File_NewClientFromConnectionString)
package main

import (
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
	"log"
	"os"
)

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

func main() {
	// Your connection string can be obtained from the Azure Portal.
	connectionString, ok := os.LookupEnv("AZURE_STORAGE_CONNECTION_STRING")
	if !ok {
		log.Fatal("the environment variable 'AZURE_STORAGE_CONNECTION_STRING' could not be found")
	}
	shareName := "testShare"
	filePath := "testDir/testFile"
	fileClient, err := file.NewClientFromConnectionString(connectionString, shareName, filePath, nil)
	handleError(err)
	fmt.Println(fileClient.URL())
}
Output:

Index

Examples

Constants

View Source
const (
	CountToEnd = 0

	// MaxUpdateRangeBytes indicates the maximum number of bytes that can be updated in a call to Client.UploadRange.
	MaxUpdateRangeBytes = 4 * 1024 * 1024 // 4MiB

	// MaxFileSize indicates the maximum size of the file allowed.
	MaxFileSize = 4 * 1024 * 1024 * 1024 * 1024 // 4 TiB

	// DefaultDownloadChunkSize is default chunk size
	DefaultDownloadChunkSize = int64(4 * 1024 * 1024) // 4MiB
)
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 AbortCopyOptions

type AbortCopyOptions struct {
	// LeaseAccessConditions contains optional parameters to access leased entity.
	// Required if the destination file has an active lease.
	LeaseAccessConditions *LeaseAccessConditions
}

AbortCopyOptions contains the optional parameters for the Client.AbortCopy method.

type AbortCopyResponse

type AbortCopyResponse = generated.FileClientAbortCopyResponse

AbortCopyResponse contains the response from method Client.AbortCopy.

type ClearRange

type ClearRange = generated.ClearRange

ClearRange - Ranges there were cleared.

type ClearRangeOptions

type ClearRangeOptions struct {
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

ClearRangeOptions contains the optional parameters for the Client.ClearRange method.

type ClearRangeResponse

type ClearRangeResponse = generated.FileClientUploadRangeResponse

ClearRangeResponse contains the response from method Client.ClearRange.

type Client

Client represents a URL to the Azure Storage file.

func NewClient added in v1.1.0

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

NewClient creates an instance of Client with the specified values.

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

Note that ClientOptions.FileRequestIntent is currently required for token authentication.

func NewClientFromConnectionString

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

NewClientFromConnectionString creates an instance of Client with the specified values.

  • connectionString - a connection string for the desired storage account
  • shareName - the name of the share within the storage account
  • filePath - the path of the file within the share
  • options - client options; pass nil to accept the default values

func NewClientWithNoCredential

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

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

  • fileURL - the URL of the file e.g. https://<account>.file.core.windows.net/share/directoryPath/file?<sas token>
  • options - client options; pass nil to accept the default values

The directoryPath is optional in the fileURL. If omitted, it points to file within the specified share.

func NewClientWithSharedKeyCredential

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

NewClientWithSharedKeyCredential creates an instance of Client with the specified values.

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

The directoryPath is optional in the fileURL. If omitted, it points to file within the specified share.

func (*Client) AbortCopy

func (f *Client) AbortCopy(ctx context.Context, copyID string, options *AbortCopyOptions) (AbortCopyResponse, error)

AbortCopy operation cancels a pending Copy File operation, and leaves a destination file with zero length and full metadata.

  • copyID: the copy identifier provided in the x-ms-copy-id header of the original Copy File operation.

For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/abort-copy-file.

func (*Client) ClearRange

func (f *Client) ClearRange(ctx context.Context, contentRange HTTPRange, options *ClearRangeOptions) (ClearRangeResponse, error)

ClearRange operation clears the specified range and releases the space used in storage for that range.

  • contentRange: Specifies the range of bytes to be cleared.

For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/put-range.

func (*Client) Create

func (f *Client) Create(ctx context.Context, fileContentLength int64, options *CreateOptions) (CreateResponse, error)

Create operation creates a new file or replaces a file. Note it only initializes the file with no content.

  • fileContentLength: Specifies the maximum size for the file in bytes, up to 4 TB.

ParseNTFSFileAttributes method can be used to convert the file attributes returned in response to NTFSFileAttributes. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/create-file.

func (*Client) Delete

func (f *Client) Delete(ctx context.Context, options *DeleteOptions) (DeleteResponse, error)

Delete operation removes the file from the storage account. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/delete-file2.

func (*Client) DownloadBuffer

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

DownloadBuffer downloads an Azure file to a buffer with parallel.

func (*Client) DownloadFile

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

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

func (*Client) DownloadStream

func (f *Client) DownloadStream(ctx context.Context, options *DownloadStreamOptions) (DownloadStreamResponse, error)

DownloadStream operation reads or downloads a file from the system, including its metadata and properties. ParseNTFSFileAttributes method can be used to convert the file attributes returned in response to NTFSFileAttributes. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-file.

func (*Client) ForceCloseHandles

func (f *Client) ForceCloseHandles(ctx context.Context, handleID string, options *ForceCloseHandlesOptions) (ForceCloseHandlesResponse, error)

ForceCloseHandles operation closes a handle or handles opened on a file.

  • handleID - Specifies the handle ID to be closed. Use an asterisk (*) as a wildcard string to specify all handles.

For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/force-close-handles.

func (*Client) GetProperties

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

GetProperties operation returns all user-defined metadata, standard HTTP properties, and system properties for the file. ParseNTFSFileAttributes method can be used to convert the file attributes returned in response to NTFSFileAttributes. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/get-file-properties.

func (*Client) GetRangeList

func (f *Client) GetRangeList(ctx context.Context, options *GetRangeListOptions) (GetRangeListResponse, error)

GetRangeList operation returns the list of valid ranges for a file. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/list-ranges.

func (*Client) GetSASURL

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

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

func (*Client) ListHandles

func (f *Client) ListHandles(ctx context.Context, options *ListHandlesOptions) (ListHandlesResponse, error)

ListHandles operation returns a list of open handles on a file. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/list-handles.

func (*Client) Rename added in v1.1.0

func (f *Client) Rename(ctx context.Context, destinationPath string, options *RenameOptions) (RenameResponse, error)

Rename operation renames a file, and can optionally set system properties for the file.

  • destinationPath: the destination path to rename the file to.

For more information, see https://learn.microsoft.com/rest/api/storageservices/rename-file.

func (*Client) Resize

func (f *Client) Resize(ctx context.Context, size int64, options *ResizeOptions) (ResizeResponse, error)

Resize operation resizes the file to the specified size. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/set-file-properties.

func (*Client) SetHTTPHeaders

func (f *Client) SetHTTPHeaders(ctx context.Context, options *SetHTTPHeadersOptions) (SetHTTPHeadersResponse, error)

SetHTTPHeaders operation sets HTTP headers on the file. ParseNTFSFileAttributes method can be used to convert the file attributes returned in response to NTFSFileAttributes. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/set-file-properties.

func (*Client) SetMetadata

func (f *Client) SetMetadata(ctx context.Context, options *SetMetadataOptions) (SetMetadataResponse, error)

SetMetadata operation sets user-defined metadata for the specified file. For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/set-file-metadata.

func (*Client) StartCopyFromURL

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

StartCopyFromURL operation copies the data at the source URL to a file.

  • copySource: specifies the URL of the source file or blob, up to 2KiB in length.

For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/copy-file.

func (*Client) URL

func (f *Client) URL() string

URL returns the URL endpoint used by the Client object.

func (*Client) UploadBuffer

func (f *Client) UploadBuffer(ctx context.Context, buffer []byte, options *UploadBufferOptions) error

UploadBuffer uploads a buffer in chunks to an Azure file.

func (*Client) UploadFile

func (f *Client) UploadFile(ctx context.Context, file *os.File, options *UploadFileOptions) error

UploadFile uploads a file in chunks to an Azure file.

func (*Client) UploadRange

func (f *Client) UploadRange(ctx context.Context, offset int64, body io.ReadSeekCloser, options *UploadRangeOptions) (UploadRangeResponse, error)

UploadRange operation uploads a range of bytes to a file.

  • offset: Specifies the start byte at which the range of bytes is to be written.
  • body: Specifies the data to be uploaded.

For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/put-range.

func (*Client) UploadRangeFromURL

func (f *Client) UploadRangeFromURL(ctx context.Context, copySource string, sourceOffset int64, destinationOffset int64, count int64, options *UploadRangeFromURLOptions) (UploadRangeFromURLResponse, error)

UploadRangeFromURL operation uploads a range of bytes to a file where the contents are read from a URL.

  • copySource: Specifies the URL of the source file or blob, up to 2 KB in length.
  • destinationRange: Specifies the range of bytes in the file to be written.
  • sourceRange: Bytes of source data in the specified range.

For more information, see https://learn.microsoft.com/en-us/rest/api/storageservices/put-range-from-url.

func (*Client) UploadStream

func (f *Client) UploadStream(ctx context.Context, body io.Reader, options *UploadStreamOptions) error

UploadStream copies the file held in io.Reader to the file at fileClient. A Context deadline or cancellation will cause this to error.

type ClientOptions

type ClientOptions base.ClientOptions

ClientOptions contains the optional parameters when creating a Client.

type CopyFileAttributes

type CopyFileAttributes = exported.CopyFileAttributes

CopyFileAttributes specifies either the option to copy file attributes from a source file(source) to a target file or a list of attributes to set on a target file.

type CopyFileChangeTime added in v1.1.0

type CopyFileChangeTime = exported.CopyFileChangeTime

CopyFileChangeTime specifies either the option to copy file change time from a source file(source) to a target file or a time value in ISO 8601 format to set as change time on a target file.

type CopyFileCreationTime

type CopyFileCreationTime = exported.CopyFileCreationTime

CopyFileCreationTime specifies either the option to copy file creation time from a source file(source) to a target file or a time value in ISO 8601 format to set as creation time on a target file.

type CopyFileLastWriteTime

type CopyFileLastWriteTime = exported.CopyFileLastWriteTime

CopyFileLastWriteTime specifies either the option to copy file last write time from a source file(source) to a target file or a time value in ISO 8601 format to set as last write time on a target file.

type CopyFileSMBInfo

type CopyFileSMBInfo struct {
	// Specifies either the option to copy file attributes from a source file(source) to a target file or a list of attributes to set on a target file.
	// CopyFileAttributes is an interface and its underlying implementation are:
	//   - SourceCopyFileAttributes - specifies to copy file attributes from a source file to a target file.
	//   - DestinationCopyFileAttributes - specifies a list of attributes to set on a target file.
	Attributes CopyFileAttributes
	// Specifies either the option to copy file change time from a source file(source) to a target file or a time value in
	// ISO 8601 format to set as change time on a target file.
	// CopyFileChangeTime is an interface and its underlying implementation are:
	//   - SourceCopyFileChangeTime - specifies to copy file change time from a source file to a target file.
	//   - DestinationCopyFileChangeTime - specifies a time value in ISO 8601 format to set as change time on a target file.
	ChangeTime CopyFileChangeTime
	// Specifies either the option to copy file creation time from a source file(source) to a target file or a time value in ISO
	// 8601 format to set as creation time on a target file.
	// CopyFileCreationTime is an interface and its underlying implementation are:
	//   - SourceCopyFileCreationTime - specifies to copy file creation time from a source file to a target file.
	//   - DestinationCopyFileCreationTime - specifies a time value in ISO 8601 format to set as creation time on a target file.
	CreationTime CopyFileCreationTime
	// Specifies either the option to copy file last write time from a source file(source) to a target file or a time value in
	// ISO 8601 format to set as last write time on a target file.
	// CopyFileLastWriteTime is an interface and its underlying implementation are:
	//   - SourceCopyFileLastWriteTime - specifies to copy file last write time from a source file to a target file.
	//   - DestinationCopyFileLastWriteTime - specifies a time value in ISO 8601 format to set as last write time on a target file.
	LastWriteTime CopyFileLastWriteTime
	// Specifies the option to copy file security descriptor from source file or to set it using the value which is defined by
	// the header value of x-ms-file-permission or x-ms-file-permission-key.
	PermissionCopyMode *PermissionCopyModeType
	// Specifies the option to overwrite the target file if it already exists and has read-only attribute set.
	IgnoreReadOnly *bool
	// Specifies the option to set archive attribute on a target file. True means archive attribute will be set on a target file
	// despite attribute overrides or a source file state.
	SetArchiveAttribute *bool
}

CopyFileSMBInfo contains a group of parameters for the FileClient.StartCopy method.

type CopyStatusType

type CopyStatusType = generated.CopyStatusType

CopyStatusType defines the states of the copy operation.

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 CreateOptions

type CreateOptions struct {
	// The default value is 'None' for Attributes and 'now' for CreationTime and LastWriteTime fields in file.SMBProperties.
	SMBProperties *SMBProperties
	// The default value is 'inherit' for Permission field in file.Permissions.
	Permissions           *Permissions
	HTTPHeaders           *HTTPHeaders
	LeaseAccessConditions *LeaseAccessConditions
	// A name-value pair to associate with a file storage object.
	Metadata map[string]*string
}

CreateOptions contains the optional parameters for the Client.Create method.

type CreateResponse

type CreateResponse = generated.FileClientCreateResponse

CreateResponse contains the response from method Client.Create.

type DeleteOptions

type DeleteOptions struct {
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

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

type DeleteResponse

type DeleteResponse = generated.FileClientDeleteResponse

DeleteResponse contains the response from method Client.Delete.

type DestinationCopyFileAttributes

type DestinationCopyFileAttributes = exported.DestinationCopyFileAttributes

DestinationCopyFileAttributes specifies a list of attributes to set on a target file.

type DestinationCopyFileChangeTime added in v1.1.0

type DestinationCopyFileChangeTime = exported.DestinationCopyFileChangeTime

DestinationCopyFileChangeTime specifies a time value in ISO 8601 format to set as change time on a target file.

type DestinationCopyFileCreationTime

type DestinationCopyFileCreationTime = exported.DestinationCopyFileCreationTime

DestinationCopyFileCreationTime specifies a time value in ISO 8601 format to set as creation time on a target file.

type DestinationCopyFileLastWriteTime

type DestinationCopyFileLastWriteTime = exported.DestinationCopyFileLastWriteTime

DestinationCopyFileLastWriteTime specifies a time value in ISO 8601 format to set as last write time on a target file.

type DestinationLeaseAccessConditions added in v1.1.0

type DestinationLeaseAccessConditions = generated.DestinationLeaseAccessConditions

DestinationLeaseAccessConditions contains optional parameters to access the destination directory.

type DownloadBufferOptions

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

	// ChunkSize specifies the chunk size to use for each parallel download; the default size is 4MB.
	ChunkSize int64

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

	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions

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

	// RetryReaderOptionsPerChunk is used when downloading each chunk.
	RetryReaderOptionsPerChunk RetryReaderOptions
}

DownloadBufferOptions contains the optional parameters for the Client.DownloadBuffer method.

type DownloadFileOptions

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

	// ChunkSize specifies the chunk size to use for each parallel download; the default size is 4MB.
	ChunkSize int64

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

	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions

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

	// RetryReaderOptionsPerChunk is used when downloading each chunk.
	RetryReaderOptionsPerChunk RetryReaderOptions
}

DownloadFileOptions contains the optional parameters for the Client.DownloadFile method.

type DownloadResponse

type DownloadResponse = generated.FileClientDownloadResponse

DownloadResponse contains the response from method FileClient.Download.

type DownloadStreamOptions

type DownloadStreamOptions struct {
	// Range specifies a range of bytes. The default value is all bytes.
	Range HTTPRange
	// When this header is set to true and specified together with the Range header, 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
	// LeaseAccessConditions contains optional parameters to access leased entity.
	// If specified, the operation is performed only if the file's lease is currently active and
	// the lease ID that's specified in the request matches the lease ID of the file.
	// Otherwise, the operation fails with status code 412 (Precondition Failed).
	LeaseAccessConditions *LeaseAccessConditions
}

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

type DownloadStreamResponse

type DownloadStreamResponse struct {
	DownloadResponse
	// contains filtered or unexported fields
}

DownloadStreamResponse contains the response from method Client.DownloadStream. 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 ForceCloseHandlesOptions

type ForceCloseHandlesOptions struct {
	// A string value that identifies the portion of the list to be returned with the next list operation. The operation returns
	// a marker value within the response body if the list returned was not complete.
	// The marker value may then be used in a subsequent call to request the next set of list items. The marker value is opaque
	// to the client.
	Marker *string
	// The snapshot parameter is an opaque DateTime value that, when present, specifies the share snapshot to query.
	ShareSnapshot *string
}

ForceCloseHandlesOptions contains the optional parameters for the Client.ForceCloseHandles method.

type ForceCloseHandlesResponse

type ForceCloseHandlesResponse = generated.FileClientForceCloseHandlesResponse

ForceCloseHandlesResponse contains the response from method Client.ForceCloseHandles.

type GetPropertiesOptions

type GetPropertiesOptions struct {
	// ShareSnapshot parameter is an opaque DateTime value that, when present, specifies the share snapshot to query for the file properties.
	ShareSnapshot *string
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

GetPropertiesOptions contains the optional parameters for the Client.GetProperties method.

type GetPropertiesResponse

type GetPropertiesResponse = generated.FileClientGetPropertiesResponse

GetPropertiesResponse contains the response from method Client.GetProperties.

type GetRangeListOptions

type GetRangeListOptions struct {
	// The previous snapshot parameter is an opaque DateTime value that, when present, specifies the previous snapshot.
	PrevShareSnapshot *string
	// Specifies the range of bytes over which to list ranges, inclusively.
	Range HTTPRange
	// The snapshot parameter is an opaque DateTime value that, when present, specifies the share snapshot to query.
	ShareSnapshot *string
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

GetRangeListOptions contains the optional parameters for the Client.GetRangeList method.

type GetRangeListResponse

type GetRangeListResponse = generated.FileClientGetRangeListResponse

GetRangeListResponse contains the response from method Client.GetRangeList.

type GetSASURLOptions

type GetSASURLOptions struct {
	StartTime *time.Time
}

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

type HTTPHeaders

type HTTPHeaders = generated.ShareFileHTTPHeaders

HTTPHeaders contains optional parameters for the Client.Create method.

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 Handle

type Handle = generated.Handle

Handle - A listed Azure Storage handle item.

type LastWrittenMode added in v1.1.0

type LastWrittenMode = generated.FileLastWrittenMode

LastWrittenMode specifies if the file last write time should be preserved or overwritten

func PossibleLastWrittenModeValues added in v1.1.0

func PossibleLastWrittenModeValues() []LastWrittenMode

PossibleLastWrittenModeValues returns the possible values for the LastWrittenMode const type.

type LeaseAccessConditions

type LeaseAccessConditions = generated.LeaseAccessConditions

LeaseAccessConditions contains optional parameters to access leased entity.

type ListHandlesOptions

type ListHandlesOptions struct {
	// A string value that identifies the portion of the list to be returned with the next list operation. The operation returns
	// a marker value within the response body if the list returned was not complete.
	// The marker value may then be used in a subsequent call to request the next set of list items. The marker value is opaque
	// to the client.
	Marker *string
	// Specifies the maximum number of entries to return. If the request does not specify maxresults, or specifies a value greater
	// than 5,000, the server will return up to 5,000 items.
	MaxResults *int32
	// The snapshot parameter is an opaque DateTime value that, when present, specifies the share snapshot to query.
	ShareSnapshot *string
}

ListHandlesOptions contains the optional parameters for the Client.ListHandles method.

type ListHandlesResponse

type ListHandlesResponse = generated.FileClientListHandlesResponse

ListHandlesResponse contains the response from method Client.ListHandles.

type ListHandlesSegmentResponse

type ListHandlesSegmentResponse = generated.ListHandlesResponse

ListHandlesSegmentResponse - An enumeration of handles.

type NTFSFileAttributes

type NTFSFileAttributes = exported.NTFSFileAttributes

NTFSFileAttributes for Files and Directories. The subset of attributes is listed at: https://learn.microsoft.com/en-us/rest/api/storageservices/set-file-properties#file-system-attributes.

func ParseNTFSFileAttributes added in v1.0.0

func ParseNTFSFileAttributes(attributes *string) (*NTFSFileAttributes, error)

ParseNTFSFileAttributes parses the file attributes from *string to *NTFSFileAttributes. It can be used to convert the file attributes to *NTFSFileAttributes where it is returned as *string type in the response. It returns an error for any unknown file attribute.

type PermissionCopyModeType

type PermissionCopyModeType = generated.PermissionCopyModeType

PermissionCopyModeType determines the copy behavior of the security descriptor of the file.

  • source: The security descriptor on the destination file is copied from the source file.
  • override: The security descriptor on the destination file is determined via the x-ms-file-permission or x-ms-file-permission-key header.
const (
	PermissionCopyModeTypeSource   PermissionCopyModeType = generated.PermissionCopyModeTypeSource
	PermissionCopyModeTypeOverride PermissionCopyModeType = generated.PermissionCopyModeTypeOverride
)

func PossiblePermissionCopyModeTypeValues

func PossiblePermissionCopyModeTypeValues() []PermissionCopyModeType

PossiblePermissionCopyModeTypeValues returns the possible values for the PermissionCopyModeType const type.

type Permissions

type Permissions = exported.Permissions

Permissions contains the optional parameters for the permissions on the file.

type RangeWriteType

type RangeWriteType = generated.FileRangeWriteType

RangeWriteType represents one of the following options.

  • update: Writes the bytes specified by the request body into the specified range. The Range and Content-Length headers must match to perform the update.
  • clear: Clears the specified range and releases the space used in storage for that range. To clear a range, set the Content-Length header to zero, and set the Range header to a value that indicates the range to clear, up to maximum file size.
const (
	RangeWriteTypeUpdate RangeWriteType = generated.FileRangeWriteTypeUpdate
	RangeWriteTypeClear  RangeWriteType = generated.FileRangeWriteTypeClear
)

func PossibleRangeWriteTypeValues

func PossibleRangeWriteTypeValues() []RangeWriteType

PossibleRangeWriteTypeValues returns the possible values for the RangeWriteType const type.

type RenameOptions added in v1.1.0

type RenameOptions struct {
	// SMBProperties contains the optional parameters regarding the SMB/NTFS properties for a file.
	SMBProperties *SMBProperties
	// Permissions contains the optional parameters for the permissions on the file.
	Permissions *Permissions
	// ContentType sets the content type of the file.
	ContentType *string
	// IgnoreReadOnly specifies whether the ReadOnly attribute on a pre-existing destination file should be respected.
	// If true, rename will succeed, otherwise, a previous file at the destination with the ReadOnly attribute set will cause rename to fail.
	IgnoreReadOnly *bool
	// A name-value pair to associate with a file storage object.
	Metadata map[string]*string
	// ReplaceIfExists specifies that if the destination file already exists, whether this request will overwrite the file or not.
	// If true, rename will succeed and will overwrite the destination file. If not provided or if false and the destination file does exist,
	// the request will not overwrite the destination file.
	// If provided and the destination file does not exist, rename will succeed.
	ReplaceIfExists *bool
	// SourceLeaseAccessConditions contains optional parameters to access the source directory.
	SourceLeaseAccessConditions *SourceLeaseAccessConditions
	// DestinationLeaseAccessConditions contains optional parameters to access the destination directory.
	DestinationLeaseAccessConditions *DestinationLeaseAccessConditions
}

RenameOptions contains the optional parameters for the Client.Rename method.

type RenameResponse added in v1.1.0

type RenameResponse struct {
	generated.FileClientRenameResponse
}

RenameResponse contains the response from method Client.Rename.

type ResizeOptions

type ResizeOptions struct {
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

ResizeOptions contains the optional parameters for the Client.Resize method.

type ResizeResponse

ResizeResponse contains the response from method Client.Resize.

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 SMBProperties

type SMBProperties = exported.SMBProperties

SMBProperties contains the optional parameters regarding the SMB/NTFS properties for a file.

type SetHTTPHeadersOptions

type SetHTTPHeadersOptions struct {
	// Resizes a file to the specified size. If the specified byte value is less than the current size of the file, then all ranges
	// above the specified byte value are cleared.
	FileContentLength *int64
	// The default value is 'preserve' for Attributes, CreationTime and LastWriteTime fields in file.SMBProperties.
	SMBProperties *SMBProperties
	// The default value is 'preserve' for Permission field in file.Permissions.
	Permissions *Permissions
	HTTPHeaders *HTTPHeaders
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

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

type SetHTTPHeadersResponse

type SetHTTPHeadersResponse = generated.FileClientSetHTTPHeadersResponse

SetHTTPHeadersResponse contains the response from method Client.SetHTTPHeaders.

type SetMetadataOptions

type SetMetadataOptions struct {
	// A name-value pair to associate with a file storage object.
	Metadata map[string]*string
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

SetMetadataOptions contains the optional parameters for the Client.SetMetadata method.

type SetMetadataResponse

type SetMetadataResponse = generated.FileClientSetMetadataResponse

SetMetadataResponse contains the response from method Client.SetMetadata.

type ShareFileRange

type ShareFileRange = generated.FileRange

ShareFileRange - An Azure Storage file range.

type ShareFileRangeList

type ShareFileRangeList = generated.ShareFileRangeList

ShareFileRangeList - The list of file ranges.

type ShareTokenIntent added in v1.1.0

type ShareTokenIntent = generated.ShareTokenIntent

ShareTokenIntent is required if authorization header specifies an OAuth token.

const (
	ShareTokenIntentBackup ShareTokenIntent = generated.ShareTokenIntentBackup
)

func PossibleShareTokenIntentValues added in v1.1.0

func PossibleShareTokenIntentValues() []ShareTokenIntent

PossibleShareTokenIntentValues returns the possible values for the ShareTokenIntent const type.

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 v1.1.1

type SourceContentValidationType interface {
	// contains filtered or unexported methods
}

SourceContentValidationType abstracts mechanisms used to validate source content

type SourceContentValidationTypeCRC64 added in v1.1.1

type SourceContentValidationTypeCRC64 uint64

SourceContentValidationTypeCRC64 is a SourceContentValidationType used to provide a precomputed CRC64.

type SourceCopyFileAttributes

type SourceCopyFileAttributes = exported.SourceCopyFileAttributes

SourceCopyFileAttributes specifies to copy file attributes from a source file(source) to a target file

type SourceCopyFileChangeTime added in v1.1.0

type SourceCopyFileChangeTime = exported.SourceCopyFileChangeTime

SourceCopyFileChangeTime specifies to copy file change time from a source file(source) to a target file.

type SourceCopyFileCreationTime

type SourceCopyFileCreationTime = exported.SourceCopyFileCreationTime

SourceCopyFileCreationTime specifies to copy file creation time from a source file(source) to a target file.

type SourceCopyFileLastWriteTime

type SourceCopyFileLastWriteTime = exported.SourceCopyFileLastWriteTime

SourceCopyFileLastWriteTime specifies to copy file last write time from a source file(source) to a target file.

type SourceLeaseAccessConditions added in v1.1.0

type SourceLeaseAccessConditions = generated.SourceLeaseAccessConditions

SourceLeaseAccessConditions contains optional parameters to access the source directory.

type SourceModifiedAccessConditions

type SourceModifiedAccessConditions = generated.SourceModifiedAccessConditions

SourceModifiedAccessConditions contains a group of parameters for the FileClient.UploadRangeFromURL method.

type StartCopyFromURLOptions

type StartCopyFromURLOptions struct {
	// A name-value pair to associate with a file storage object.
	Metadata map[string]*string
	// required if x-ms-file-permission-copy-mode is specified as override
	Permissions     *Permissions
	CopyFileSMBInfo *CopyFileSMBInfo
	// LeaseAccessConditions contains optional parameters to access leased entity.
	// Required if the destination file has an active lease.
	LeaseAccessConditions *LeaseAccessConditions
}

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

type StartCopyFromURLResponse

type StartCopyFromURLResponse = generated.FileClientStartCopyResponse

StartCopyFromURLResponse contains the response from method Client.StartCopyFromURL.

type TransferValidationType

type TransferValidationType = exported.TransferValidationType

TransferValidationType abstracts the various mechanisms used to verify a transfer.

type TransferValidationTypeMD5

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 Share/Directory/File 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.

type UploadBufferOptions

type UploadBufferOptions = uploadFromReaderOptions

UploadBufferOptions provides set of configurations for Client.UploadBuffer operation.

type UploadFileOptions

type UploadFileOptions = uploadFromReaderOptions

UploadFileOptions provides set of configurations for Client.UploadFile operation.

type UploadRangeFromURLOptions

type UploadRangeFromURLOptions struct {
	// Only Bearer type is supported. Credentials should be a valid OAuth access token to copy source.
	CopySourceAuthorization *string
	// SourceContentValidation contains the validation mechanism used on the range of bytes read from the source.
	SourceContentValidation        SourceContentValidationType
	SourceModifiedAccessConditions *SourceModifiedAccessConditions
	LeaseAccessConditions          *LeaseAccessConditions
	// LastWrittenMode specifies if the file last write time should be preserved or overwritten.
	LastWrittenMode *LastWrittenMode

	// Deprecated: Specify the crc64 calculated for the range of bytes that must be read from the copy source.
	SourceContentCRC64 uint64
}

UploadRangeFromURLOptions contains the optional parameters for the Client.UploadRangeFromURL method.

type UploadRangeFromURLResponse

type UploadRangeFromURLResponse = generated.FileClientUploadRangeFromURLResponse

UploadRangeFromURLResponse contains the response from method Client.UploadRangeFromURL.

type UploadRangeOptions

type UploadRangeOptions struct {
	// TransactionalValidation specifies the transfer validation type to use.
	// The default is nil (no transfer validation).
	TransactionalValidation TransferValidationType
	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
	// LastWrittenMode specifies if the file last write time should be preserved or overwritten.
	LastWrittenMode *LastWrittenMode
}

UploadRangeOptions contains the optional parameters for the Client.UploadRange method.

type UploadRangeResponse

type UploadRangeResponse = generated.FileClientUploadRangeResponse

UploadRangeResponse contains the response from method Client.UploadRange.

type UploadStreamOptions

type UploadStreamOptions struct {
	// ChunkSize defines the size of the buffer used during upload. The default and minimum value is 1 MiB.
	// Maximum size of a chunk is MaxUpdateRangeBytes.
	ChunkSize int64

	// Concurrency defines the max number of concurrent uploads to be performed to upload the file.
	// Each concurrent upload will create a buffer of size ChunkSize.  The default value is one.
	Concurrency int

	// LeaseAccessConditions contains optional parameters to access leased entity.
	LeaseAccessConditions *LeaseAccessConditions
}

UploadStreamOptions provides set of configurations for Client.UploadStream operation.

Jump to

Keyboard shortcuts

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