[Zope] Images and uploading

Paul Zwarts paul.zwarts@oratrix.com
Wed, 28 Feb 2001 12:13:54 +0100


Hi all,

I've progressed on with LocalFS and feel comfortable with it, but Im
having difficulties with uploading images.

I really need to get the content_type attribute of the image, so I can
store in the dbms with its record what file extension it is... I thought
of querying the getProperty of the REQUEST stream, but it doesnt seem to
work the way I expected.

What happens with:
Case A)
      <dtml-call
expr="LinkImgMnt[_.str(SESSION['key2'])].manage_upload(id=_.string.replace(ltitle,'
','+'), file=REQUEST['image'])">
      <br><font class="text2"><dtml-var
"LinkImgMnt[_.str(SESSION['key2'])][_.string.replace(ltitle,'
','+')].getProperty('content_type')"></font>


Case B)
      <dtml-call
expr="LinkImgMnt[_.str(SESSION['key2'])].manage_upload(id=_.string.replace(ltitle,'
','+') + '.jpg', file=REQUEST['image'])">
      <br><font class="text2"><dtml-var
"LinkImgMnt[_.str(SESSION['key2'])][_.string.replace(ltitle,' ','+') +
'.jpg'].getProperty('content_type')"></font>



So, obviously LinkImgMnt is the LocalFS mount. and I need to give the
names of the files + for whitespace.
The vars after that is my test.

Case A) I try to query the content type of the file AFTER I've deposited
it. But I note that without providing the extension in the
manage_upload, I get application/octet-stream. Which is totally
acceptable and proof of working, but not desired outcome. Its a GIF that
went through _image_.

Case B) Doing the same thing, only appending .jpg to the id, I get the
right answer back... at least, I get AN answer. But since _image_ is a
gif, then obviously Im jury rigging it to give me what I asked for...

So the question is, how do I get an attribute of an object while its
still masquerading in the REQUEST as an upload instance....? Other
reasons being is that on my old system, (its a link databse) hackers
tried to upload .exe's thinking they could get a server-side trojan
running, so I provide some kind of error checking....

Help much appreciated...
Paz