[Zope] (possible) Answer to: What to do if manage_addImage uploads are corrupted?

Samu Mielonen ex@uiah.fi
Sun, 24 Oct 1999 15:31:02 +0300


I had a problem:

 using manage_addImage to create an image inside a Zope folder
 out of a submit form REQUEST object resulted in a image
 file with content type text/plain and wrong size (i.e.
 my REQUEST.image turned out to be a string object and not
 an image object, resulting in text string being saved
 as an image).

Both Martin and Alexander recommended the following:

> <form action="..." method="post" enctype="multipart/form-data">
>   ...
> </form>

Duh!

(i.e. if you do not specify in your submit form the encoding type
 and that you are sending multi-part data, then the image will not
 be uploaded. Only the pathname to the image will be uploaded).

<crawling under the rock in shame and swearing to check one's own code
 in the *right* place before posting>

Thank you :)

You wouldn't know how to test if a REQUEST.image1 exists or not before
actually using manage_addImage or manage_upload on that image?

Using any of the following if conditions always return TRUE (regardless of
whether I've picked an image to be uploaded in my submit form). Please note
that image1 is from: <input type=file name=image1> tag that is part of the
form that sends the multipart/encoded data to the following dtml-method:

  <dtml-if image1>

  <dtml-if "image1">

  <dtml-if "REQUEST.image1">

  <dtml-if "not image1==''">

  <dtml-if "not REQUEST.image1==''">

Because the if-clause (any of above) always returns true, I end up 
saving NOTHING in place of an image when the submit form didn't 
include an image (via property image1).

Best regards,
	Samu Mielonen

PS BTW, I couldn't find a reference to enctype="multipart/form-data"
in any of the broken image upload messages in archives, so I posted
this to the list as well.