MCPcopy
hub / github.com/tinode/chat / upload

Function upload

tn-cli/commands.py:405–429  ·  view source on GitHub ↗
(id, cmd, args)

Source from the content-addressed store, hash-verified

403
404# Upload file out of band over HTTP(S) (not gRPC).
405def 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
432def fileUpload(id, cmd, args):

Callers

nothing calls this directly

Calls 3

handle_ctrlFunction · 0.90
dotdictClass · 0.90
stdoutlnFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…