Ir.attachement downloading a file through RPC

I have uploaded file through RPC and can retrieve data (name/description) OK, but I’m not sure how to retrieve the file.

This is the way I upload/create:

    const payload = {
      id: '1',
      method: '',
      params: [[{data: {"__class__": "bytes", "base64": data.file}, "description": data.documentType,  "name":, "resource": `,${data.customerId}`}], {}],

This is what I tried to download an attachment:

    const payload = {
      id: '1',
      method: '',
      params: [[['resource','=',`,${}`]], null, null, null, ['id', 'resource', 'name', 'description', 'create_date', 'data'], {}],

Any help appreciated, thanks.

And what is the problem?


I want to retrieve an uploaded file. I can retrieve name/description but don’t see how to retrieve the file. I tried the data field but nothing is returned.

What does it mean? Could you provide the complete information of what you do?

I want to retrieve the attachment using an RPC call.

Well we can not help you if you do not provide the information about you do, what are your results and what you would expect.

I’m not sure what you’re asking for that isn’t in this thread already?

I want to do an JSON-RPC hit to download an attachment from ir.attachment as stated above. How do I do that?

If it’s search_read how do I get the file? What field do I need to request? If it’s another method, what is the method to use for getting the file from ir.attachment?

You’ve merely posted only the payload of what you’re sending.
We don’t know anything about the context in which this payload is used (this does not look like sao’s code), what errors you’ve received (or absence of errors), etc.

The attachments are stored in the model ir.attachment, you can read this model just like any other model in tryton using read. The field that you’d like to read to fetch the attachement data is named data.

search_read is a specific method that does both a search and a read.

I posted in the title ‘ir.attachment downloading a file through RPC’ - that was my goal

In my first message I posted my payload that wasn’t working. Simply looking at the payload and saying this is right or wrong would have been a good start as a reply no?

Nevertheless, I have it working now, it turned out to be a tryton issue I assume as having restarted tryton I now get the data field, prior nothing was returned for the data field, it was empty no matter what attachment I tried to download.