fix: check whether file exists before downloading the file by using stream parameter #43
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, sostatus=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.