Files¶
Description
Using files with Archetype field
local
Download URL for files for ATFile content¶
Append
@@download
view to URL.
Checking whether a File field has uploaded content¶
Calling AT File field accessor will return a
File
object:
(Pdb) self.context.getAttachment()
<File at /mfabrik/success-stories/case-studies/finnish-national-broadcasting-company/attachment>
Note that this may return
None
if the content item has been constructed but the form has
not been properly saved.
If the size is
0
, the file is not yet uploaded:
(Pdb) attach.getSize()
0
Example how to check in a view whether AT context file size exists:
@property
def available(self):
# Make sure that we have content item of right kind
if ICaseStudy.providedBy(self.context):
# Make sure the content item is not anymore in the creation stage
if self.context.getAttachment() is not None:
# Check the content of File field
if self.context.getAttachment().getSize() > 0:
return True
return False