(id, cmd, args)
| 403 | |
| 404 | # Upload file out of band over HTTP(S) (not gRPC). |
| 405 | def upload(id, cmd, args): |
| 406 | try: |
| 407 | from client import handle_ctrl |
| 408 | scheme = 'https' if args.ssl else 'http' |
| 409 | try: |
| 410 | from importlib.metadata import version |
| 411 | except ImportError: |
| 412 | from importlib_metadata import version |
| 413 | LIB_VERSION = version("tinode_grpc") |
| 414 | |
| 415 | result = requests.post( |
| 416 | scheme + '://' + args.web_host + '/v' + PROTOCOL_VERSION + '/file/u/', |
| 417 | headers = { |
| 418 | 'X-Tinode-APIKey': args.api_key, |
| 419 | 'X-Tinode-Auth': 'Token ' + tn_globals.AuthToken, |
| 420 | 'User-Agent': APP_NAME + " " + APP_VERSION + "/" + LIB_VERSION |
| 421 | }, |
| 422 | data = {'id': id}, |
| 423 | files = {'file': (cmd.filename, open(cmd.filename, 'rb'))}) |
| 424 | handle_ctrl(dotdict(json.loads(result.text)['ctrl'])) |
| 425 | |
| 426 | except Exception as ex: |
| 427 | stdoutln("Failed to upload '{0}'".format(cmd.filename), ex) |
| 428 | |
| 429 | return None |
| 430 | |
| 431 | |
| 432 | def fileUpload(id, cmd, args): |
nothing calls this directly
no test coverage detected
searching dependent graphs…