Re: [Zope] Viewing images from a form upload

2006-07-11 Thread Jonathan

Pls keep your posts on the list...

- Original Message - 
From: "vl" <[EMAIL PROTECTED]>

To: "Jonathan" <[EMAIL PROTECTED]>
Sent: Tuesday, July 11, 2006 4:01 PM
Subject: Re: [Zope] Viewing images from a form upload





Jonathan wrote:


- Original Message - From: "vl" <[EMAIL PROTECTED]>
To: 
Sent: Tuesday, July 11, 2006 3:07 PM
Subject: [Zope] Viewing images from a form upload


I am stuck on trying to preview images that are uploaded from a html 
form.


enctype="multipart/form-data">




When the form is submited it sends it to a python script that gets the 
image and sends it to another page to be previewed.  Problem is, I 
receive and error that the image cannot be displayed.


My python script is below.

REQUEST=context.REQUEST
content_type=file.headers['Content-Type']
if content_type.find('image')!=-1:
context.REQUEST.RESPONSE.setHeader('Content-Type', 'image/jpg')
img = file.read()
print context.dtml_select_new_image(context, context.REQUEST, 
image=img)

return printed
else:
return "error"

I load the image in a dtml method with:



The dtml-var tag creates an html img tag which your browser then uses to 
make another HTTP call to the server to acquire the image file. This 
means that the image data must be saved on the server (ie. you cannot 
return the image data in the initial response).


So, your process should be:

1) get the image data from the form
2) save an image object somewhere
3) pass back an html img tag with the path/id of the saved image object
Is saving the image the only way of viewing it?  I can view the image if I 
return it in the python script like:


context.REQUEST.RESPONSE.setHeader('Content-Type', 'image/jpg')
img = file.read()
return img

The image will display.  But I need to view it in a dtml-method.


If you want to use plain vanilla html then you need to use the img tag to 
display the image.  The img tag causes the browser to initiate a new http 
request to the server, therefore the server needs a way to return the image 
(ie. a path/id).


There are two ways (that I know of, but there are probably other ways) 
around this situation:


1) store the image in a temporary folder (a folder that uses RAM not written 
to disk via the zodb); you need to be careful with memory utilization with 
this approach.


2) you may be able to send the data back in a javascript variable and then 
execute javascript on the browser in order to display the image 
(mulit-browser support will be an issue with this option)




Jonathan 


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Viewing images from a form upload

2006-07-11 Thread Jonathan


- Original Message - 
From: "vl" <[EMAIL PROTECTED]>

To: 
Sent: Tuesday, July 11, 2006 3:07 PM
Subject: [Zope] Viewing images from a form upload



I am stuck on trying to preview images that are uploaded from a html form.

enctype="multipart/form-data">




When the form is submited it sends it to a python script that gets the 
image and sends it to another page to be previewed.  Problem is, I receive 
and error that the image cannot be displayed.


My python script is below.

REQUEST=context.REQUEST
content_type=file.headers['Content-Type']
if content_type.find('image')!=-1:
context.REQUEST.RESPONSE.setHeader('Content-Type', 'image/jpg')
img = file.read()
print context.dtml_select_new_image(context, context.REQUEST, 
image=img)

return printed
else:
return "error"

I load the image in a dtml method with:



The dtml-var tag creates an html img tag which your browser then uses to 
make another HTTP call to the server to acquire the image file. This means 
that the image data must be saved on the server (ie. you cannot return the 
image data in the initial response).


So, your process should be:

1) get the image data from the form
2) save an image object somewhere
3) pass back an html img tag with the path/id of the saved image object

hth

Jonathan


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )


Re: [Zope] Viewing images from a form upload

2006-07-11 Thread David H

vl wrote:

I am stuck on trying to preview images that are uploaded from a html 
form.


enctype="multipart/form-data">




When the form is submited it sends it to a python script that gets the 
image and sends it to another page to be previewed.  Problem is, I 
receive and error that the image cannot be displayed.


My python script is below.
REQUEST=context.REQUEST
content_type=file.headers['Content-Type']
if content_type.find('image')!=-1:
context.REQUEST.RESPONSE.setHeader('Content-Type', 'image/jpg')
img = file.read()
print context.dtml_select_new_image(context, context.REQUEST, 
image=img)

return printed
else:
return "error"

I load the image in a dtml method with:

___


Vi,

Your kind of vague but one thing i'd change is:

 print context.dtml_select_new_image(context, context.REQUEST, image=img)
to
 return context.dtml_select_new_image(context, context.REQUEST, image=img)

David


___
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
http://mail.zope.org/mailman/listinfo/zope-announce

http://mail.zope.org/mailman/listinfo/zope-dev )