Sorry for long posting this thread. When posting using JSOn we need to user base64.
When go back to python, we need to change back to byte so it can be read.
Here I posted the solution. Hope it can help to others:
class Attachment(metaclass=PoolMeta):
__name__ = "ir.attachment"
@classmethod
def __setup__(cls):
super().__setup__()
cls.__rpc__.update(
{
"rft_attachment": RPC(readonly=False),
}
)
@classmethod
def rft_attachment(cls, values, *args):
if not values:
return
pool = Pool()
Attachment = pool.get("ir.attachment")
val = values[0]
base64data = val["data"]
filename = val["filename"]
resource = val["resource"]
imgdata = base64.b64decode(base64data)
(attach,) = Attachment.create(
[
{
"resource": resource,
"name": filename,
"data": imgdata,
}
]
)
return [{"value": True}]