Skip to content

Instantly share code, notes, and snippets.

@jeffotoni
Created August 6, 2020 14:35
Show Gist options
  • Select an option

  • Save jeffotoni/2325691ec6c3032da5ffa960f4835b63 to your computer and use it in GitHub Desktop.

Select an option

Save jeffotoni/2325691ec6c3032da5ffa960f4835b63 to your computer and use it in GitHub Desktop.
func createMultipartFormData(t *testing.T, fieldName, fileName string) (bytes.Buffer, *multipart.Writer) {
var b bytes.Buffer
var err error
w := multipart.NewWriter(&b)
var fw io.Writer
file := mustOpen(fileName)
if fw, err = w.CreateFormFile(fieldName, file.Name()); err != nil {
t.Errorf("Error creating writer: %v", err)
}
if _, err = io.Copy(fw, file); err != nil {
t.Errorf("Error with io.Copy: %v", err)
}
w.Close()
return b, w
}
func mustOpen(f string) *os.File {
r, err := os.Open(f)
if err != nil {
pwd, _ := os.Getwd()
fmt.Println("PWD: ", pwd)
panic(err)
}
return r
}
@jeffotoni
Copy link
Author

curl -X POST
http://localhost:9091/storage/add
-H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
-F owner=0xc916Cfe5c83dD4FC3c3B0Bf2ec2d4e401782875e
-F password=$PWD
-F file=@./internal/file_example_JPG_500kB.jpg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment