omarryhan/aiogoogle

Ability to upload from AsyncIterable object

Closed this issue · 6 comments

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!

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!!

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!!

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

done :)

Released in v4.3.0, thanks!

Related: #98