Skip to content

Instantly share code, notes, and snippets.

@MakotoE
Last active December 9, 2019 22:48
Show Gist options
  • Save MakotoE/7fca93b2e89707015f4c5fe4bb8c7565 to your computer and use it in GitHub Desktop.
Save MakotoE/7fca93b2e89707015f4c5fe4bb8c7565 to your computer and use it in GitHub Desktop.
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