Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: Getting final Url (from redirect) on presentation upload
  • Loading branch information
gustavotrott committed Aug 17, 2023
1 parent 6c047f1 commit 0e21fcd
Showing 1 changed file with 13 additions and 4 deletions.
Expand Up @@ -12,14 +12,12 @@
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.entity.ContentType;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClients;
Expand Down Expand Up @@ -197,6 +195,7 @@ private String followRedirect(String meetingId, String redirectUrl,
conn.setReadTimeout(60000);
conn.addRequestProperty("Accept-Language", "en-US,en;q=0.8");
conn.addRequestProperty("User-Agent", "Mozilla");
conn.setInstanceFollowRedirects(false);

// normally, 3xx is redirect
int status = conn.getResponseCode();
Expand Down Expand Up @@ -287,10 +286,20 @@ public boolean savePresentation(final String meetingId,
String finalUrl = followRedirect(meetingId, urlString, 0, urlString);

if (finalUrl == null) return false;
if(!finalUrl.equals(urlString)) {
log.info("Redirected to Final URL [{}]", finalUrl);
}

boolean success = false;

CloseableHttpAsyncClient httpclient = HttpAsyncClients.createDefault();
//Disable follow redirect since finalUrl already did it
RequestConfig requestConfig = RequestConfig.custom()
.setRedirectsEnabled(false)
.build();

CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom()
.setDefaultRequestConfig(requestConfig)
.build();
try {
httpclient.start();
File download = new File(filename);
Expand Down

0 comments on commit 0e21fcd

Please sign in to comment.