You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* By default, Resty streams the content in the request body when a file or `io.Reader` is detected in the MultipartField input.
70
-
* Only allowed on POST, PUT, and PATCH HTTP verbs.
75
+
* Only allowed on POST, PUT, and PATCH verbs.
71
76
*[Request.SetMultipartBoundary]({{% godoc v3 %}}Request.SetMultipartBoundary) setting custom boundary can be used together.
77
+
* All form data and multipart methods can be used together.
72
78
{{% /hint %}}
73
79
74
80
## Upload
75
81
76
-
### Simple
82
+
```go
83
+
// add one file
84
+
client.R().
85
+
SetFile("my_file", "/path/to/file/sample.pdf") // field name and file path
86
+
87
+
// add multiple files together
88
+
client.R().
89
+
SetFiles(map[string]string{
90
+
// field name and file path
91
+
"my_file1": "/path/to/file/sample1.pdf",
92
+
"my_file2": "/path/to/file/sample2.pdf",
93
+
"my_file3": "/path/to/file/sample3.pdf",
94
+
})
95
+
```
77
96
78
-
### File with Content-Type
97
+
### Use io.Reader
79
98
80
-
### Combine Form Data and Files Together
99
+
```go
100
+
// adding bytes or io.Reader
101
+
client.R().
102
+
SetFileReader(
103
+
"profile_img", // field name
104
+
"my-profile-img.png", // file name
105
+
bytes.NewReader(profileImgBytes), // io.Reader
106
+
)
107
+
```
108
+
109
+
### With Content-Type
110
+
111
+
```go
112
+
// adding bytes or io.Reader with file content-type
113
+
client.R().
114
+
SetMultipartField(
115
+
"profile_img", // field name
116
+
"my-profile-img.png", // file name
117
+
"image/png", // file content-type
118
+
bytes.NewReader(profileImgBytes), // io.Reader
119
+
)
120
+
```
81
121
82
122
## Upload Progress
83
123
124
+
Resty v3 provides an optional multipart live upload progress count in bytes, see
125
+
*[Request.SetMultipartFields]({{% godoc v3 %}}Request.SetMultipartFields) - it is quite powerful, supports various combinations, [see example](#power-of-requestsetmultipartfields)
126
+
*[MultipartField]({{% godoc v3 %}}MultipartField) input type
127
+
* Refer to the godoc to know more about `Optional` fields.
0 commit comments