|
8 | 8 | "io" |
9 | 9 | "mime/multipart" |
10 | 10 | "net/http" |
11 | | - "os" |
12 | 11 |
|
13 | 12 | drycc "github.com/drycc/controller-sdk-go" |
14 | 13 | "github.com/drycc/controller-sdk-go/api" |
@@ -43,23 +42,16 @@ func GetFile(c *drycc.Client, appID, volumeID, path string) (*http.Response, err |
43 | 42 | } |
44 | 43 |
|
45 | 44 | // 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) { |
47 | 46 | buffer := new(bytes.Buffer) |
48 | 47 | 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 |
60 | 52 | } |
61 | 53 |
|
62 | | - if err := writer.WriteField("path", path); err != nil { |
| 54 | + if err := writer.WriteField("path", volumePath); err != nil { |
63 | 55 | return nil, err |
64 | 56 | } |
65 | 57 | writer.Close() |
|
0 commit comments