forked from hunternet93/ddp_asyncio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_upload_file.py
38 lines (28 loc) · 1.22 KB
/
example_upload_file.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
'''An example application that uses ddp_asyncio's MeteorFilesUploader to upload a file to an instance of Meteor-Files' demo application (https://github.com/VeliovGroup/Meteor-Files-Demos)'''
import asyncio
import sys
import logging
logger = logging.getLogger('websockets')
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())
from ddp_asyncio import DDPClient
from ddp_asyncio.extras import MeteorFilesUploader
class DemoUploader:
def __init__(self, address):
self.client = DDPClient(address)
self.uploader = MeteorFilesUploader(self.client, 'uploadedFiles')
async def go(self, filename, loop):
await self.client.connect()
print('Starting upload...')
upload = self.uploader.start_upload(filename, loop = loop, meta = {
'blamed': 0,
'secured': False,
'unlisted': False
})
while not upload.complete:
print('{:.1f}% uploaded'.format(upload.progress * 100))
await asyncio.sleep(1)
print('Upload complete. File ID: {}'.format(upload._id))
du = DemoUploader(sys.argv[1])
loop = asyncio.get_event_loop()
loop.run_until_complete(du.go(sys.argv[2], loop))