Skip to content

Commit 0b1023f

Browse files
committed
chore(filer): change PostFile method params
1 parent 6be4f71 commit 0b1023f

2 files changed

Lines changed: 13 additions & 15 deletions

File tree

volumes/filer.go

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"io"
99
"mime/multipart"
1010
"net/http"
11-
"os"
1211

1312
drycc "github.com/drycc/controller-sdk-go"
1413
"github.com/drycc/controller-sdk-go/api"
@@ -43,23 +42,16 @@ func GetFile(c *drycc.Client, appID, volumeID, path string) (*http.Response, err
4342
}
4443

4544
// Put file to an app's volume.
46-
func PostFile(c *drycc.Client, appID, volumeID, path string, files ...string) (*http.Response, error) {
45+
func PostFile(c *drycc.Client, appID, volumeID, volumePath, name string, reader io.Reader) (*http.Response, error) {
4746
buffer := new(bytes.Buffer)
4847
writer := multipart.NewWriter(buffer)
49-
for _, file := range files {
50-
f, err := os.Open(file)
51-
if err != nil {
52-
return nil, err
53-
}
54-
defer f.Close()
55-
if part, err := writer.CreateFormFile("file", f.Name()); err != nil {
56-
return nil, err
57-
} else if _, err = io.Copy(part, f); err != nil {
58-
return nil, err
59-
}
48+
if part, err := writer.CreateFormFile("file", name); err != nil {
49+
return nil, err
50+
} else if _, err = io.Copy(part, reader); err != nil {
51+
return nil, err
6052
}
6153

62-
if err := writer.WriteField("path", path); err != nil {
54+
if err := writer.WriteField("path", volumePath); err != nil {
6355
return nil, err
6456
}
6557
writer.Close()

volumes/filer_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,13 @@ func TestVolumesPostFile(t *testing.T) {
141141
t.Fatal(err)
142142
}
143143

144-
if _, err := PostFile(drycc, "example-go", "myvolume", "tmp/", testFile); err != nil {
144+
file, err := os.Open(testFile)
145+
if err != nil {
146+
t.Fatal(err)
147+
}
148+
defer file.Close()
149+
150+
if _, err := PostFile(drycc, "example-go", "myvolume", "tmp/", file.Name(), file); err != nil {
145151
t.Fatal(err)
146152
}
147153

0 commit comments

Comments
 (0)