Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
1814 Vistas

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
Descartar
Mejor respuesta

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
Descartar
Autor

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.

Mejor respuesta

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
Descartar
Autor

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.

Publicaciones relacionadas Respuestas Vistas Actividad
1
ago 25
131
3
ago 25
399
3
ago 25
1647
1
jul 25
676
0
ago 25
539