Created
August 6, 2020 14:35
-
-
Save jeffotoni/2325691ec6c3032da5ffa960f4835b63 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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 | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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