Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check whether file exists before downloading the file by using stream parameter #43

Merged
merged 1 commit into from
Sep 19, 2024

Conversation

kan-fu
Copy link
Collaborator

@kan-fu kan-fu commented Sep 9, 2024

This PR fixes a bug that the client library should not download the file if the file exists and overwrite=False. Previosly, it downloads the file first, then checks if the file exists, which wastes bandwidth.

By using stream=True parameter, the requests method can postpone the download. saveAsFile will handle the actual stream download, and also return the download time and file size.

Initially I tried using HEAD first to avoid the download. Turns out it requires a bigger code change (download the file in status=200 branch). I also met some difficulties like HEAD does not have a body, so status=202 cannot use response.json(). Using stream can keep the current code logic unchanged.

The test failure can be ignored. It is a backend bug, which will be fixed in the backend later.

@kan-fu kan-fu merged commit 6859a94 into main Sep 19, 2024
3 of 6 checks passed
@kan-fu kan-fu deleted the issue-41-stream-requests branch September 19, 2024 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

overwrite parameter = False in download methods should prevent downloading if file exists
3 participants