2 #assumes that jupload send files one by one.
3 from Products
.CMFCore
.exceptions
import BadRequest
4 from Products
.CMFCore
.utils
import getToolByName
5 from Products
.Plinn
.utils
import makeValidId
6 form
= context
.REQUEST
.form
7 ctr
= getToolByName(context
, 'content_type_registry')
9 file = [form
[name
] for name
in form
.keys() if name
.startswith('File')][0]
10 filename
= file.filename
11 utf8filename
= filename
.split('%25')[0]
12 if utf8filename
!= filename
:
13 for p
in filename
.split('%25')[1:] :
14 utf8filename
+= chr(int(p
[0:2], 16)) + p
[2:]
15 filename
= utf8filename
17 allow_dup
= form
.get('overwrite', False)
18 id = makeValidId(context
, filename
, allow_dup
=allow_dup
)
19 mt
= form
['mimetype[]']
21 # adapted from plone jupload
22 pt
= ctr
.findTypeName(id.lower(), mt
, file)
24 id = context
.invokeFactory( type_name
=pt
,
28 o
= getattr(context
, id)
32 o
= getattr(context
, id)
33 if o
.meta_type
== 'Photo' :
40 # looks like the constructor does no support a file argument
41 # (probably trying to create a cmf document)
42 context
.invokeFactory( type_name
=pt
,
44 text_format
=mt
.split('/')[1],