-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Using pipe_to and pipe_from #98
Comments
As I understand, pipe_to should work with an async buffer, couldn't find one though. |
Hey @Shmookoff , An example has been added here: 0a27589 |
Oh, sorry, just realized that all you can see is print |
Does this help: 5008af0 ? |
Maybe you can wrap the IOBase with a generator? pipe_to expects a class with a generator method. You think that would work? |
I think it is fair to say that my programming skills are not on this level yet, so.. I would really love some more explanation 🙂 |
I think I found something. |
I worked it out! This is a compiled example from the pieces of my project. from io import BytesIO
from aiofiles.tempfile import TemporaryFile
async def main():
async with Aiogoogle(user_creds=user_creds, client_creds=client_creds) as aiogoogle:
drive_v3 = await aiogoogle.discover("drive", "v3")
async with TemporaryFile("wb+") as async_buffer:
await aiogoogle.as_user(
drive_v3.files.get(fileId=file_id, pipe_to=async_buffer, alt="media")
)
await async_buffer.seek(0)
contents = await async_buffer.read()
buffer = BytesIO(contents) I do not guarrante the example working, as I haven't tested this. For all I can say, in my project it works. I think the idea is clear though. @omarryhan, what do you think? |
Oh nevermind, I thought the current API expected a generator. Sorry, was on my phone yesterday all day, so couldn't look in depth into this. Even if it was a generator, I'm not really sure if that would work :) Great solution! I'm open to adding a better API if you think it would be more efficient and simpler than the current approach. Also, for sure adding an example with the code you shared above would be a good idea. Thanks!! @Shmookoff |
Sorry for long time to answer, had to focus on my own project for a little while. As I said, I don't think I have the knowledge to think of a new API. Developing my project, I also ran into async with Aiogoogle(
service_account_creds=ServiceAccountCreds(**config.google, scopes=scopes)
) as aiogoogle:
drive = await aiogoogle.discover("drive", "v3")
with open("README.md", "rb") as file:
contents = file.read()
async with TemporaryFile("wb+") as async_buffer:
await async_buffer.write(contents)
await async_buffer.seek(0)
req = drive.files.create(pipe_from=async_buffer)
await aiogoogle.as_service_account(req) Raises: I tried to bypass async with Aiogoogle(
service_account_creds=ServiceAccountCreds(**config.google, scopes=scopes)
) as aiogoogle:
drive = await aiogoogle.discover("drive", "v3")
with open("README.md", "rb") as file:
contents = file.read()
req = drive.files.create()
req.media_upload = MediaUpload(contents)
await aiogoogle.as_service_account(req) But, as I quickly realized, it pretty much is imposiible. I'll be adding a PR with examples for |
For now, I found a workaround to my problem. req = drive.files.create(pipe_from=True)
req.media_upload.file_body = contents
req.media_upload.pipe_from = None This is, of course, fairly ugly and not intended. |
Nice workaround And yeah, I agree having |
I can't really find anything in docs about the use of pipe_to.
The only clarification I could find is this, where bytes get just printed out.
What buffer does it need? How do I use it?
Can someone please clarify this for me.
The text was updated successfully, but these errors were encountered: