@@ -162,10 +162,18 @@ sub request {
162
162
163
163
my $req_method = ' request' ;
164
164
my $req = [ $verb , $url , $options ];
165
+ my $boundary ;
165
166
166
- if ($verb eq ' POST' and ref ($content ) eq ' HASH' and $content -> {file }) {
167
+ if (( $verb eq ' POST' or $verb eq ' PUT ' ) and ref ($content ) eq ' HASH' and $content -> {file }) {
167
168
$content = { %$content };
168
- my $file = path( delete $content -> {file } );
169
+ my $file = delete $content -> {file };
170
+
171
+ my $key = (keys %$file )[0]
172
+ if (ref $file );
173
+
174
+ $file = (ref $file )
175
+ ? path( $file -> {$key } )
176
+ : path( $file );
169
177
170
178
unless (-f $file and -r $file ) {
171
179
local $Carp::Internal { ' GitLab::API::v4' } = 1;
@@ -183,18 +191,34 @@ sub request {
183
191
},
184
192
};
185
193
186
- $req -> [0] = $req -> [1]; # Replace method with url.
187
- $req -> [1] = $data ; # Put data where url was.
188
- # So, req went from [$verb,$url,$options] to [$url,$data,$options],
189
- # per the post_multipart interface.
190
-
191
- $req_method = ' post_multipart' ;
192
- $content = undef if ! %$content ;
194
+ if ($verb eq ' POST' ) {
195
+ $req -> [0] = $req -> [1]; # Replace method with url.
196
+ $req -> [1] = $data ; # Put data where url was.
197
+ # So, req went from [$verb,$url,$options] to [$url,$data,$options],
198
+ # per the post_multipart interface.
199
+
200
+ $req_method = ' post_multipart' ;
201
+ $content = undef if ! %$content ;
202
+ } elsif ($verb eq ' PUT' ) {
203
+ $boundary .= sprintf (" %x " , rand 16) for 1..16;
204
+ $content = <<"EOL" ;
205
+ --------------------------$boundary
206
+ Content-Disposition: form-data; name="$key "; filename="$data ->{file}->{filename}"
207
+
208
+ $data ->{file}->{content}
209
+ --------------------------$boundary --
210
+ EOL
211
+ }
193
212
}
194
213
195
- if (ref $content ) {
196
- $content = $self -> json-> encode( $content );
197
- $headers -> {' content-type' } = ' application/json' ;
214
+ if (defined $boundary or ref $content ) {
215
+ $content = $self -> json-> encode( $content )
216
+ if (ref $content );
217
+
218
+ $headers -> {' content-type' } = (defined $boundary )
219
+ ? " multipart/form-data; boundary=------------------------$boundary "
220
+ : ' application/json' ;
221
+
198
222
$headers -> {' content-length' } = length ( $content );
199
223
}
200
224
0 commit comments