Warning

This document hasn't been checked for compatibility with current versions of Plone. Use at your own risk.

Howto integrate JUpload to upload multiple files

by Laurence Rowe last modified Dec 06, 2009 09:27 PM
Enable your users to upload multiple files by hacking the JUpload applet and integrating it with Plone

Placeholder so I don't forget to write this up properly

You need to hack cookie support into JUpload and use the files attached...

This is the uplaod script:

    request = context.REQUEST
    user = request.AUTHENTICATED_USER
    userid = user.getUserName()

    ctr = context.content_type_registry
    mtr = context.mimetypes_registry #becasue application/octet-stream is useless

    form = request.form

    for formname in form:
       #must not iterate over form values direcly or get unauthorized errors
       file = form[formname]
       filename=file.filename
       id = filename[max( filename.rfind('/')
                      , filename.rfind('\\')
                      , filename.rfind(':') )+1:]
       mt = str(mtr.classify(data=file, filename=filename))
       pt = ctr.findTypeName(id, mt, file)
       #import pdb; pdb.set_trace()
       if pt == 'Document':
           obname = context.invokeFactory(type_name=pt, id=id)
           ob = context[obname]
           ob = context.portal_factory.doCreate(ob)
           ob.edit(text_format=mt, text='', file=file)
       else:
           obname = context.invokeFactory(type_name=pt, id=id, file=file)
           ob = context[obname]
           ob = context.portal_factory.doCreate(ob)

       print pt+' : '+id+", "

    print 'By ' + userid
    return printed

Contribute

Something wrong or out of date? Anybody can edit or create a new article in the knowledge base. Simply create an account on this site, log in, and click the Edit button to contribute.