Em Sexta 19 Maio 2006 10:13, Julio Oña escreveu:
> Hi,
>
> I'm doing:
>
> while defining fields for form
>
> class myForm(widgets.WidgetsList):
>     pdf =  widgets.FileField(name="pdf", label=_("PDF File"), validator=
> validators.FileUploadKeeper())
>     ...
>
> while processing result from form
>
> @expose
> def savePDF(self, pdf, ...): 
>     file = pdf.value
>     f=open('/tmp/workfile', 'w')
>     f.write(file)
>     f.close()

I used a different approach.

The form:

        form = widgets.TableForm(fields = [
            widgets.FileField(
            name = 'image',
            label = _('Some picture'),
            validator = validators.FieldStorageUploadConverter())
           ])


Saving the image to the database:

    @expose()
    @validate(validators = {
        'image': validators.FieldStorageUploadConverter()
        })
    def save(self, image):
        image = model.Image(
            fileName = image.filename,
            image = image.file.read(),
        )
        return dict(image_id = image.id)


Retrieving the image from the database:

    @turbogears.expose(content_type = "image/jpg")
    def show_image(self, image_id):
        # "model.Image.q.image is where the image is stored
        return model.Image.get(image_id).image


Of course, if you need some pre-processing -- such as resizing, creating 
thumbnails, etc. -- you need to "image.file.read()" before saving the image 
to the database.


Thanks, Julio!


Be seeing you,
-- 
Jorge Godoy      <[EMAIL PROTECTED]>


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to