(filepath, size=1024*1024)
| 431 | |
| 432 | def fileUpload(id, cmd, args): |
| 433 | def iter_file(filepath, size=1024*1024): |
| 434 | _, name = os.path.split(filepath) |
| 435 | mimeType = mimetypes.guess_type(filepath)[0] |
| 436 | with open(filepath, mode='rb') as fd: |
| 437 | try: |
| 438 | yield pb.FileUpReq(id=str(id), auth=pb.Auth(scheme='token', secret=tn_globals.AuthToken), |
| 439 | topic="", meta=pb.FileMeta(name=name, mime_type=mimeType, size=0)) |
| 440 | while True: |
| 441 | chunk = fd.read(size) |
| 442 | if chunk: |
| 443 | yield pb.FileUpReq(content=chunk) |
| 444 | else: # Finished. |
| 445 | break |
| 446 | except Exception as ex: |
| 447 | stdoutln("Failed to read '{0}':".format(cmd.filename), ex) |
| 448 | |
| 449 | try: |
| 450 | response = pbx.NodeStub(tn_globals.Connection).LargeFileReceive(iter_file(cmd.filename)) |
no test coverage detected
searching dependent graphs…