Skip to content

Commit 405180f

Browse files
author
Thomas Hanke
committed
fix redirect issue
1 parent 91df925 commit 405180f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

app.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ def open_file(uri: AnyUrl, authorization=None) -> Tuple["filedata":str, "filenam
203203
detail=f"{uri} is not a valid URI - if local file add file:// as prefix. Error: {str(e)}",
204204
) from e
205205
else:
206-
filename = unquote(uri_parsed.path).rsplit("/download/upload")[0].split("/")[-1]
207206
if uri_parsed.scheme in ["https", "http"]:
208207
# r = urlopen(uri)
209208
s = requests.Session()
@@ -218,6 +217,13 @@ def open_file(uri: AnyUrl, authorization=None) -> Tuple["filedata":str, "filenam
218217
status_code=r.status_code, detail="cant get file at {}".format(uri)
219218
)
220219
filedata = r.content
220+
# Extract filename from the FINAL URL after redirects, not the original URL
221+
final_url = r.url
222+
final_url_parsed = urlparse(final_url)
223+
filename = unquote(final_url_parsed.path).rsplit("/download/upload")[0].split("/")[-1]
224+
logging.debug(f"Original URL: {uri}")
225+
logging.debug(f"Final URL after redirects: {final_url}")
226+
logging.debug(f"Extracted filename: {filename}")
221227
# charset=r.info().get_content_charset()
222228
# if not charset:
223229
# charset='utf-8'

0 commit comments

Comments
 (0)