-
Notifications
You must be signed in to change notification settings - Fork 6
How to upload files
Mark Sullivan edited this page Apr 8, 2019
·
2 revisions
When using send_stream_request
Errbot Stream is expecting a BinaryIO
so use open('/path/to/file/filename.ext','r')
for fsource
.
After calling send_stream_request
an errbot.backend.base.Stream()
will be returned. This can be used to monitor the state of the transfer. See the following example:
from time import sleep
from errbot import BotPlugin, botcmd
from errbot.backends import base
class Example(BotPlugin):
@botcmd # flags a command
def tryme(self, msg, args): # a command callable with !tryme
stream = self._bot.send_stream_request(identifier=msg.frm,
fsource=open('/path/to/file/filename.ext', 'r'),
name='filename.ext')
while True:
sleep(5)
yield stream.status
if stream.status == base.STREAM_ERROR:
yield "Transfer stopped with error"
return
if stream.status == base.STREAM_SUCCESSFULLY_TRANSFERED:
yield "Transfer completed successfully"
return