Skip to content

Commit 1d73815

Browse files
Merge pull request #24 from robinverduijn/JENKINS-50772-set-s3-content-type
JENKINS-50772: Enhance uploadFile so that it optionally sets a "Content-Type" header.
2 parents 60593aa + 2d2a3c9 commit 1d73815

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/main/java/io/jenkins/plugins/httpclient/RobustHTTPClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,22 @@ public static String sanitize(URL url) {
239239
* Upload a file to a URL.
240240
*/
241241
public void uploadFile(File f, URL url, TaskListener listener) throws IOException, InterruptedException {
242+
uploadFile(f, null, url, listener);
243+
}
244+
245+
/**
246+
* Upload a file to a URL with a specific content type.
247+
*
248+
* @param f the file to upload
249+
* @param contentType the content type for the specified file
250+
*/
251+
public void uploadFile(File f, String contentType, URL url, TaskListener listener) throws IOException, InterruptedException {
242252
connect("upload", "upload " + f + " to " + sanitize(url), client -> {
243253
HttpPut put = new HttpPut(url.toString());
244254
put.setEntity(new FileEntity(f));
255+
if (contentType != null) {
256+
put.setHeader("Content-Type", contentType);
257+
}
245258
return client.execute(put);
246259
}, response -> {}, listener);
247260
}

0 commit comments

Comments
 (0)