Created
February 2, 2018 20:39
-
-
Save ehotinger/9589082621a692aba6668ea820ea1c6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"log" | |
"net/url" | |
"strings" | |
"github.com/Azure/azure-storage-blob-go/2016-05-31/azblob" | |
) | |
var ( | |
blobURL = "" | |
) | |
func main() { | |
p := azblob.NewPipeline(azblob.NewAnonymousCredential(), azblob.PipelineOptions{}) | |
// Create a ContainerURL object that wraps a soon-to-be-created blob's URL and a default pipeline. | |
u, _ := url.Parse(blobURL) | |
appendBlobURL := azblob.NewAppendBlobURL(*u, p) | |
ctx := context.Background() // This example uses a never-expiring context | |
// Overwrite the blob if one exists using the specified SAS URL. | |
_, err := appendBlobURL.Create(ctx, azblob.Metadata{}, azblob.BlobHTTPHeaders{}, azblob.BlobAccessConditions{}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
for i := 0; i < 5; i++ { | |
_, err := appendBlobURL.AppendBlock(ctx, strings.NewReader(fmt.Sprintf("Appending block #%d\n", i)), azblob.BlobAccessConditions{}) | |
log.Println("Appending blob....") | |
if err != nil { | |
log.Fatal(err) | |
} | |
r, err := appendBlobURL.SetMetadata(ctx, azblob.Metadata{}, azblob.BlobAccessConditions{}) | |
if err != nil { | |
log.Fatal(err) | |
} | |
log.Printf("Status code: '%d'", r.StatusCode()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment