Skip to Content
Menu
This question has been flagged
2 Replies
1291 Views

Hi,

How does the pdf files content have been encoded in Odoo file system. I managed to find the location where the encoded file are get stored. But get stuck how to decode the file content. 

Hoping someone has the solution?


Image of my encoded pdf file content


Thank you!

Avatar
Discard
Best Answer

Files like PDFs are typically stored in the database as binary data, often encoded in base64 format. Decode the base64-encoded data using base64.b64decode().Write the decoded content to a file or process it as needed.

pdf_content = base64.b64decode(record.datas)

with open('decoded_file.pdf', 'wb') as f: f.write(pdf_content)

Avatar
Discard
Author

Thanks for your answer, but I actually checked the database, and the ir_attachment model contains the content of only txt, csv, and rtf files. It does not contain the content of PDF files. That's why I checked the filestore folder of my on-premises instance, and there I was able to find the PDF file in an encoded form. I tried decoding it using Base64, but it didn't work.

FYI: I found the respective file in the filestore of the Odoo instance using its store_fname field value in ir_attachment.

Best Answer

Attachments stored outside the database are not encoded.

The ir.attachment record stores the name of the original file in NAME and the name of the filestore folder and file in STORE_FNAME.

To restore the original file, copy the filestore file from the folder and rename it to what is stored in NAME.


Avatar
Discard
Author

Thanks for your answer, Ray. But checked the content it was encoded. I can't be able to attach image in the comment section, so I updated the image of the encoded file in my question itself.

You are just showing the contents of a regular PDF file.

Do the same thing with a file never uploaded to Odoo and it will look the same.

Rename that file from the filestore with a PDF extension to verify - it will just open in your PDF viewer.

Related Posts Replies Views Activity
0
Apr 25
4
1
Apr 25
397
1
Feb 25
449
1
Jan 25
579
2
Jan 25
466