Skip to content

Instantly share code, notes, and snippets.

@MakotoE MakotoE/appendBlobTest.go
Last active Dec 9, 2019

Embed
What would you like to do?
package main
import (
"bytes"
"context"
"fmt"
"github.com/Azure/azure-storage-blob-go/azblob"
"mime/multipart"
"net/http/httptest"
"net/url"
"reflect"
)
func main() {
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile("file.txt", "file.txt")
if err != nil {
panic(err)
}
part.Write([]byte("file contents"))
writer.Close()
r := httptest.NewRequest("POST", "/", body)
r.Header.Add("Content-Type", writer.FormDataContentType())
file, _, err := r.FormFile("file.txt")
if err != nil {
panic(err)
}
fmt.Println(reflect.ValueOf(file).Kind()) // struct
fmt.Println(reflect.ValueOf(file).Kind() == reflect.Struct)
var v *multipart.File
v = &file
fmt.Println(reflect.ValueOf(v).Kind()) // ptr
if err := Upload(v); err != nil {
panic(err)
}
}
func Upload(file *multipart.File) error {
u, _ := url.Parse("blob url")
appendBlobURL := azblob.NewAppendBlobURL(
*u,
azblob.NewPipeline(nil, azblob.PipelineOptions{}),
)
// What do I do here?
_, err := appendBlobURL.AppendBlock(context.Background(), file, azblob.AppendBlobAccessConditions{}, nil)
return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.