Question

I have a custom Dexterity type that utilizes plone.formwidget.multifile.MultiFileFieldWidget:

class ITestimony(form.Schema):
    ...
    form.widget(files=MultiFileFieldWidget)
    files = schema.List(
        title=_(u"Files"),
        value_type=NamedFile()
    )

Everything goes well as expected when editing the item:

enter image description here

Here is the relevant view template, that I try borrow from https://developer.plone.org/reference_manuals/external/plone.app.dexterity/advanced/files-and-images.html:

<fieldset tal:condition="context/files">
<legend>Attached Files</legend>
  <ul>
  <tal:files repeat="item context/files">
    <li><a href=""
         tal:attributes="href string:${context/absolute_url}/@@download/files/${item/filename};"
         tal:content="item/filename">Attached File</a></li>
  </tal:files>
  </ul>
</fieldset>

I want the attached files can be downloaded by clicking on the links. But I get error with my current template:

AttributeError: 'list' object has no attribute 'getSize'

enter image description here

How can I download my uploaded files?

Was it helpful?

Solution

Actually the answer is from http://josh.postach.io/multiple-file-upload-custom-dexterity-content-types-plone-5-02a

The following snippet works for me:

<fieldset tal:condition="context/files">
<legend>Attached Files</legend>
<ul>
  <tal:files repeat="item context/files">
  <li><a href=""
    tal:attributes="href string:${context/absolute_url}/@@edit/++widget++form.widgets.files/@@download/${repeat/item/index}"
    tal:content="item/filename">Attached File</a></li>
  </tal:files>
</ul>
</fieldset>

Although using @@edit is wired here, hopefully we will have better version of plone.formwidget.multifile or related packages soon.

OTHER TIPS

Some notes about how files are handled with Dexterity are here:

http://developer.plone.org/forms/files.html

Specifically, constructing download URLs:

http://developer.plone.org/forms/files.html#connstring-download-urls

(@@download helper view)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top