In Odoo 12, We are using ir.attachment to store JSON files. In some of the attachments, the file content is missing somehow. File size, Stored Filename, and Mime type are still there and we're keeping condition if there is a JSON file, only then we're creating ir.attachment records. It is just file content(datas) is empty somehow for some of the records.
Any idea what could be the issue?
Method we're following to create attachment:
def create_attachment(self, file_name=False, file=False):
if file and file_name:
file = base64.encodestring(file)
attachment_id = self.env['ir.attachment'].create({
'name': file_name,
'datas': file,
'datas_fname': file_name,
'type': 'binary',
'res_model': 'res.partner',
'res_id': self.id,
})
The thing it's that if some records are created with content and others not, that means that your attachment creation code it's ok.
You need to check the code that produce the JSON file content and check if you are really getting the proper data values for the attachment creation.
Or you are saying that the content of those files dissappear after a while? Also you can go directly to the filestore db folder and check the file that it's located at the
store_fnamelocation inside the filestore db folderThe filestore location it's controlled by the odoo config option
data_dirwith a default value~/.local/share/Odoo/filestore/relative to the local user home folder in Linux. Could have another value in a different OS