Hi,
HELP! ;)
I am trying to create image upload functionality to have the following
features:
1/. Uploading to start as soon as image is chosen
2/. Progress meter
3/. Next file field created on the fly
4/. Thumbnail prior to completion
None of this is new functionality. 1/. is doable with the RemoteForm
widget, 2/. is the uploadfilter, 3/. is some pretty straightforward JS
requesting a new FileFields instance and the FileFields widget does
4/. However none of these pieces play together very well. :(
I decided to start by getting FileFields and uploadfilter to work but
it is proving tricky. Hopefully due mostly to my own lack of
understanding.
As I see it the problem I have is that uploadfilter creates a
temporary file in order to monitor the upload and somehow doesn't hand
this over to FileFields the way FileFields expects it. Specifically
after a file is uploaded FileFields tries to use it and gets the
following error:
File "/usr/local/lib/python2.4/site-packages/TurboGears-1.0.1-
py2.4.egg/turbogears/controllers.py", line 143, in validate
kw.update(form.validate(value, state))
File "/usr/local/lib/python2.4/site-packages/TurboGears-1.0.1-
py2.4.egg/turbogears/widgets/forms.py", line 1166, in validate
return self.validator.to_python(value, state)
File "/usr/local/lib/python2.4/site-packages/FormEncode-0.7-
py2.4.egg/formencode/api.py", line 368, in to_python
value = tp(value, state)
File "/usr/local/lib/python2.4/site-packages/FormEncode-0.7-
py2.4.egg/formencode/schema.py", line 132, in _to_python
new[name] = validator.to_python(value, state)
File "/usr/local/lib/python2.4/site-packages/FormEncode-0.7-
py2.4.egg/formencode/api.py", line 368, in to_python
value = tp(value, state)
File "/Users/aj/Development/workspace/uploadII.py", line 286, in
_to_python
file = super(ImageValidator, self)._to_python(value, state)
File "/Users/aj/Development/workspace/uploadII.py", line 102, in
_to_python
size=self.get_file_size(info.file))
File "/Users/aj/Development/workspace/uploadII.py", line 64, in
get_file_size
size = file.tell()
AttributeError: 'ProgressFile' object has no attribute 'tell'
I tried making ProgressFile inherit from 'file' but then it just
complains that the file is closed:
File "/Users/aj/Development/workspace/uploadII.py", line 64, in
get_file_size
size = file.tell()
ValueError: I/O operation on closed file
Digging about and I find that maybe FileFields shouldn't be using
'tell' on the temporary file - the cgi source says that the file
produced by FieldStorage.make_file only needs to support reading,
writing and seek(0).
My current thinking is that a hack in
FileValidator.get_associated_file might be the way forward but I don't
know enough about the request object to pull the correct file out of
it.
Any ideas? Anybody?
AJ
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---