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

signals: "file_downloaded" sent too early #180

Open
slint opened this issue Jun 7, 2018 · 2 comments
Open

signals: "file_downloaded" sent too early #180

slint opened this issue Jun 7, 2018 · 2 comments
Milestone

Comments

@slint
Copy link
Member

slint commented Jun 7, 2018

The file_downloaded signal is sent too early during the file download request. This is bad for e.g. invenio-stats, which relies on the signal for gathering file download statistics. In case the download is interrupted for some reason (e.g. connection dropped or the user canceled the download), the signal will already have been sent.

A possible solution is to use the flask.after_this_request callback, and send the signal afterward if the request was successful (i.e. 2xx/3xx).

slint added a commit to slint/invenio-files-rest that referenced this issue Jun 7, 2018
* Sends the 'file_download' signal after the end of the request.
  (closes inveniosoftware#180)
@lnielsen
Copy link
Member

lnielsen commented Jun 7, 2018

In case send_file() sends a redirect (e.g. x-sendfile) won't this be the same problem?

@slint
Copy link
Member Author

slint commented Jun 7, 2018

True. In general, after some local testing, apparently, it's not easy (if even possible at all) to keep track of when a file was actually downloaded or if the connection was dropped... One idea is using werkzeug.wsgi.ClosingIterator which can execute a callback after the .close() is called for the file, but this still doesn't solve the issue...

(TBH the issue rises from what COUNTER and other discussions related to datasets/files would like to track about files. One of the things e.g. is the total transferred volume of a dataset/file, which one cannot know unless we know that the file arrived someplace...)

@lnielsen lnielsen added this to the someday milestone Feb 19, 2019
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

No branches or pull requests

2 participants