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

Ability to upload from AsyncIterable object #101

Closed
erangalon opened this issue Aug 8, 2022 · 6 comments
Closed

Ability to upload from AsyncIterable object #101

erangalon opened this issue Aug 8, 2022 · 6 comments

Comments

@erangalon
Copy link
Contributor

Hi! I have a use case where I need to upload a file that is read from an async generator. Currently, the pipe_from accepts a file-like object with a read() function, is it possible to add support for an AsyncIterable object, something like this:

    async def aiter_file(self, aiter_func):
        if self.file_path:
            async for chunk in aiter_func(self.file_path, self.chunk_size):
                yield chunk
        elif self.pipe_from:
            if isinstance(self.pipe_from, AsyncIterable):
                async for chunk in self.pipe_from:
                    yield chunk
            else:
                yield self.pipe_from.read()
        else:
            async for chunk in self._aiter_body():
                yield chunk

I tested this and it works great, I'll be happy to open a PR for this.

Thanks!

@omarryhan
Copy link
Owner

Looks good to me, backwards compatible and stdlib Python!
Would you be so kind and add an example as well showing how to use it using an AsyncIterable?
Also, referring to the example in the documentation would be great. Thanks!!

@erangalon
Copy link
Contributor Author

created pull request:
#102

I couldn't find who to refer to the example in the documentation, if you can point me there I'll add it.

Thanks!!

@omarryhan
Copy link
Owner

Thanks for the PR!

Maybe refer to the example you added to /examples dir in this section of the docs: https://aiogoogle.readthedocs.io/en/latest/#upload-a-file-to-google-drive

@erangalon
Copy link
Contributor Author

done :)

@omarryhan
Copy link
Owner

Released in v4.3.0, thanks!

@omarryhan
Copy link
Owner

Related: #98

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