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

Allow to abort Upload with MultipartEncoderMonitor #297

Open
paulmueller opened this issue Jul 16, 2020 · 1 comment
Open

Allow to abort Upload with MultipartEncoderMonitor #297

paulmueller opened this issue Jul 16, 2020 · 1 comment

Comments

@paulmueller
Copy link

For uploading large files with MultipartEncoderMonitor, it would be helpful to be able to abort the upload. I think this could be done conveniently with the callback function, i.e. instead of

def read(self, size=-1):
string = self.encoder.read(size)
self.bytes_read += len(string)
self.callback(self)
return string

one could do something like:

 def read(self, size=-1): 
     string = self.encoder.read(size) 
     self.bytes_read += len(string) 
     cb = self.callback(self)
     if cb is None:
         # The callback function normally returns `None`.
         return string 
     else:
         # If it returns something else, the upload is stopped by raising an Exception.
         # This exception can be caught in a try-except statement wrapping around
         # the `requests.post(...` call.
         raise MultipartEncoderAbort("MultipartEncoder streaming aborted by callback: {}".format(cb))

What do you think? Could something like this be included in requests_toolbelt or should I subclass MultipartEncoderMonitor in my own projects for this purpose?

@sigmavirus24
Copy link
Collaborator

The hard thing to reason about here is how this interacts with Requests and the remote server. As suggested, this doesn't seem wise.

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