MCPcopy Index your code
hub / github.com/tinode/chat / attachment

Function attachment

tn-cli/utils.py:127–146  ·  view source on GitHub ↗
(filename)

Source from the content-addressed store, hash-verified

125
126# Create a drafty message with an *in-band* attachment.
127def attachment(filename):
128 try:
129 f = open(filename, 'rb')
130 # Try to guess the mime type.
131 mimetype = mimetypes.guess_type(filename)[0]
132 data = base64.b64encode(f.read())
133 # python3 fix.
134 if type(data) is not str:
135 data = data.decode()
136 result = {
137 'fmt': [{'at': -1}],
138 'ent': [{'tp': 'EX', 'data':{
139 'val': data, 'mime': mimetype, 'name':os.path.basename(filename)
140 }}]
141 }
142 f.close()
143 return result
144 except IOError as err:
145 stdoutln("Error processing attachment '" + filename + "':", err)
146 return None
147
148
149# encode_to_bytes converts the 'src' to a byte array.

Callers 1

pubMsgFunction · 0.90

Calls 1

stdoutlnFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…