|
2 | 2 | package volumes |
3 | 3 |
|
4 | 4 | import ( |
5 | | - "bytes" |
6 | 5 | "encoding/json" |
7 | 6 | "fmt" |
8 | 7 | "io" |
9 | | - "mime/multipart" |
10 | 8 | "net/http" |
11 | 9 | "net/url" |
12 | | - "strings" |
13 | 10 |
|
14 | 11 | drycc "github.com/drycc/controller-sdk-go" |
15 | 12 | "github.com/drycc/controller-sdk-go/api" |
@@ -45,29 +42,14 @@ func GetFile(c *drycc.Client, appID, volumeID, path string) (*http.Response, err |
45 | 42 |
|
46 | 43 | // Put file to an app's volume. |
47 | 44 | func PostFile(c *drycc.Client, appID, volumeID, volumePath, name string, size int64, reader io.Reader) (*http.Response, error) { |
48 | | - |
49 | | - buffer := new(bytes.Buffer) |
50 | | - writer := multipart.NewWriter(buffer) |
51 | | - if err := writer.WriteField("path", volumePath); err != nil { |
52 | | - return nil, err |
53 | | - } |
54 | | - if _, err := writer.CreateFormFile("file", name); err != nil { |
55 | | - return nil, err |
56 | | - } |
57 | | - size += int64(buffer.Len()) |
58 | | - head := strings.NewReader(buffer.String()) |
59 | | - buffer.Reset() |
60 | | - writer.Close() |
61 | | - bottom := strings.NewReader(buffer.String()) |
62 | | - size += int64(buffer.Len()) |
63 | 45 | u := fmt.Sprintf("/v2/apps/%s/volumes/%s/client/", appID, volumeID) |
64 | | - |
65 | | - r, err := c.NewRequest("POST", u, io.MultiReader(head, reader, bottom)) |
| 46 | + r, err := c.NewRequest("POST", u, reader) |
66 | 47 | if err != nil { |
67 | 48 | return nil, err |
68 | 49 | } |
69 | 50 | r.ContentLength = size |
70 | | - r.Header.Add("Content-Type", writer.FormDataContentType()) |
| 51 | + r.Header.Add("Content-Type", "filer/octet-stream") |
| 52 | + r.Header.Add("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filepath="%s"`, name, volumePath)) |
71 | 53 | return c.Do(r) |
72 | 54 | } |
73 | 55 |
|
|
0 commit comments