--- /dev/null
+##parameters=command, path, file='', Type='', redirUrl=''
+
+from Products.CMFCore.utils import getToolByName
+
+def replaceXMLEntities(text) :
+ for c, ent in (('<', '<'), ('>', '>'), ('&', '&')) :
+ text = text.replace(c, ent)
+ return text
+
+utool = getToolByName(context, 'portal_url')
+atool = getToolByName(context, 'portal_attachment')
+
+portal = utool.getPortalObject()
+
+ob = portal
+path = path.strip('/')
+
+ob = portal
+path = path.strip('/')
+
+for name in path.split('/') :
+ ob = getattr(ob, name)
+
+if command == 'ls':
+ attachments = atool.getAttachmentsFor(ob)
+ attachments = attachments.objectValues()
+
+ print '<ls>'
+ for o in attachments :
+ size = o.getThumbnailSize()
+ row = '<row previewUrl="%(previewUrl)s" url="%(url)s" meta_type="%(meta_type)s" width="%(width)d" height="%(height)d">%(title)s</row>' % {
+ 'previewUrl' : '%s/getThumbnail' % o.absolute_url(),
+ 'url' : 'attachments/%s' % o.getId(),
+ 'meta_type' : o.meta_type,
+ 'title' : replaceXMLEntities(o.title_or_id()),
+ 'width' : size['width'],
+ 'height' : size['height']
+ }
+ print row
+ print '</ls>'
+
+if command == 'upload' :
+ atool.uploadAttachmentFor(ob, file, typeName=Type)
+ return context.REQUEST.RESPONSE.redirect(redirUrl);
+
+if command == 'rm' :
+ ob = context.restrictedTraverse(path)
+ parent = ob.getParentNode()
+ parent.manage_delObjects(ob.getId())
+ print '<done/>'
+
+
+context.REQUEST.RESPONSE.setHeader('content-type', 'text/xml; charset=utf-8')
+return printed
\ No newline at end of file