I want to add some properties ‘on file download’. What is the ‘correct’ way of doing this. Basically, I want to add ‘properties’ to word, which I think I can do with ‘docx’.
Should I just override the ‘@@download’ view?
Basically I (just) want to do this (probably check for mimetype instead of 'filename
if filename.lower().endswith(".docx"):
try:
doc = Document(BytesIO(file_data))
props = doc.core_properties
props.title = item.Title() or "File from XXXXX"
props.author = "Somebody"
props.subject = "Requested document"
props.keywords = "Plone, etc"
buffer = BytesIO()
doc.save(buffer)
file_data = buffer.getvalue()
except Exception as e:
pass
I would modify it when uploading, adding the properties. You can keep also the original version with CMFEditions, and serve the modified one. It depends on the use case, loading in memory and modifying a file at each download seems heavy to me. Pdfs has incremental updates that can help, you can stream the original file and then just add modifications at the end. I don’t know if docx has this feature.