@@ -523,7 +523,7 @@ protected Response post(StreamingOutput stream, String mediaType, Object... path
523
523
}
524
524
525
525
/**
526
- * Perform a file upload as part of the , returning
526
+ * Perform a file upload using the specified media type , returning
527
527
* a ClientResponse instance with the data returned from the endpoint.
528
528
*
529
529
* @param name the name for the form field that contains the file name
@@ -561,6 +561,45 @@ protected Response upload(String name, File fileToUpload, String mediaTypeString
561
561
}
562
562
}
563
563
564
+ /**
565
+ * Perform a file upload using multipart/form-data using the HTTP PUT method, returning
566
+ * a ClientResponse instance with the data returned from the endpoint.
567
+ *
568
+ * @param name the name for the form field that contains the file name
569
+ * @param fileToUpload a File instance pointing to the file to upload
570
+ * @param mediaTypeString the content-type of the uploaded file, if null will be determined from fileToUpload
571
+ * @param pathArgs variable list of arguments used to build the URI
572
+ * @return a ClientResponse instance with the data returned from the endpoint
573
+ * @throws IOException if an error occurs while constructing the URL
574
+ */
575
+ protected Response putUpload (String name , File fileToUpload , String mediaTypeString , Object ... pathArgs ) throws IOException {
576
+ URL url = getApiUrl (pathArgs );
577
+ return (putUpload (name , fileToUpload , mediaTypeString , url ));
578
+ }
579
+
580
+ /**
581
+ * Perform a file upload using multipart/form-data using the HTTP PUT method, returning
582
+ * a ClientResponse instance with the data returned from the endpoint.
583
+ *
584
+ * @param name the name for the form field that contains the file name
585
+ * @param fileToUpload a File instance pointing to the file to upload
586
+ * @param mediaTypeString the content-type of the uploaded file, if null will be determined from fileToUpload
587
+ * @param url the fully formed path to the GitLab API endpoint
588
+ * @return a ClientResponse instance with the data returned from the endpoint
589
+ * @throws IOException if an error occurs while constructing the URL
590
+ */
591
+ protected Response putUpload (String name , File fileToUpload , String mediaTypeString , URL url ) throws IOException {
592
+
593
+ MediaType mediaType = (mediaTypeString != null ? MediaType .valueOf (mediaTypeString ) : null );
594
+ try (MultiPart multiPart = new FormDataMultiPart ()) {
595
+ FileDataBodyPart filePart = mediaType != null ?
596
+ new FileDataBodyPart (name , fileToUpload , mediaType ) :
597
+ new FileDataBodyPart (name , fileToUpload );
598
+ multiPart .bodyPart (filePart );
599
+ return (invocation (url , null ).put (Entity .entity (multiPart , MULTIPART_FORM_DATA_TYPE )));
600
+ }
601
+ }
602
+
564
603
/**
565
604
* Perform an HTTP PUT call with the specified form data and path objects, returning
566
605
* a ClientResponse instance with the data returned from the endpoint.
0 commit comments