Skip to content

Commit

Permalink
[JENKINS-51402] Presigned url has the wrong region
Browse files Browse the repository at this point in the history
when running from a different one
  • Loading branch information
carlossg committed May 22, 2018
1 parent ea314b9 commit 83fa829
Showing 1 changed file with 3 additions and 1 deletion.
Expand Up @@ -354,6 +354,8 @@ public Void invoke(File f, VirtualChannel channel) throws IOException, Interrupt
* Upload a file to a URL
*/
private static void uploadFile(Path f, URL url) throws IOException {
// AWS will redirect to the bucket region if different
HttpURLConnection.setFollowRedirects(true);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod("PUT");
Expand All @@ -362,7 +364,7 @@ private static void uploadFile(Path f, URL url) throws IOException {
Files.copy(f, out);
}
int responseCode = connection.getResponseCode();
if (responseCode < 200 || responseCode >= 300) {
if (responseCode < 200 || responseCode >= 400) {
throw new IOException(String.format("Failed to upload %s to %s, response: %d %s", f.toAbsolutePath(), url,
responseCode, connection.getResponseMessage()));
}
Expand Down

0 comments on commit 83fa829

Please sign in to comment.