Fix downloading file by URL (Windows) (#1958)

as_posix() needed so that backslashes are output as forward slashes in the URL string (Windows)

Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
alex-fdias 2022-06-29 17:18:08 +01:00 committed by GitHub
parent 7ec9614961
commit b3244d05cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -343,7 +343,7 @@ def check_file(file, suffix=''):
if Path(file).is_file() or file == '': # exists
return file
elif file.startswith(('http:/', 'https:/')): # download
url = str(Path(file)).replace(':/', '://') # Pathlib turns :// -> :/
url = str(Path(file).as_posix()).replace(':/', '://') # Pathlib turns :// -> :/
file = Path(urllib.parse.unquote(file).split('?')[0]).name # '%2F' to '/', split https://url.com/file.txt?auth
if Path(file).is_file():
print(f'Found {url} locally at {file}') # file already exists