-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from NabilMostafa/stream-uploaded-files
Stream uploaded files
- Loading branch information
Showing
5 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/python3.7 | ||
|
||
''' | ||
Scopes Required: | ||
* https://www.googleapis.com/auth/drive | ||
* https://www.googleapis.com/auth/drive.file | ||
API explorer link: | ||
* https://developers.google.com/apis-explorer/#p/drive/v3/drive.files.create | ||
''' | ||
|
||
import asyncio | ||
|
||
from helpers import Aiogoogle, user_creds, client_creds | ||
|
||
|
||
class MyFile: | ||
@staticmethod | ||
async def read(): | ||
return b'Hello World' | ||
|
||
|
||
async def stream_upload_file(): | ||
async with Aiogoogle(user_creds=user_creds, client_creds=client_creds) as aiogoogle: | ||
# Create API | ||
drive_v3 = await aiogoogle.discover("drive", "v3") | ||
|
||
req = drive_v3.files.create( | ||
pipe_from=MyFile(), | ||
fields="id" | ||
) | ||
|
||
# Upload file | ||
upload_res = await aiogoogle.as_user(req) | ||
print(f"Uploaded stream file successfully.\nFile ID: {upload_res['id']}") | ||
|
||
if __name__ == "__main__": | ||
asyncio.run(stream_upload_file()) |