后端下载进度条打印

This commit is contained in:
hjdhnx 2023-11-18 15:54:27 +08:00
parent 4a4252e0cd
commit 8c10762705
2 changed files with 4 additions and 3 deletions

View File

@ -1 +1 @@
3.9.48beta26 3.9.48beta27

View File

@ -51,7 +51,8 @@ def get_file_name(url, headers):
def file_download(fileUrl, filePath): def file_download(fileUrl, filePath):
if os.path.exists(filePath): if os.path.exists(filePath):
os.remove(filePath) os.remove(filePath)
response = requests.get(fileUrl, headers=headers, stream=True, verify=False) # response = requests.get(fileUrl, headers=headers, stream=True, verify=False)
response = requests.get(fileUrl, headers=headers, stream=True)
fileSize = int(response.headers['content-length']) # 文件大小 fileSize = int(response.headers['content-length']) # 文件大小
logger.info(f'fileSize:{fileSize}') logger.info(f'fileSize:{fileSize}')
@ -76,7 +77,7 @@ def file_download(fileUrl, filePath):
if remainSize > 0: if remainSize > 0:
with closing(requests.get(fileUrl, headers=_headers, stream=True, verify=False)) as _response, open( with closing(requests.get(fileUrl, headers=_headers, stream=True)) as _response, open(
filePath, filePath,
"ab") as file: "ab") as file:
for content in _response.iter_content(chunk_size=chunkSize): for content in _response.iter_content(chunk_size=chunkSize):