[Zope] stupid file upload question

Joh Johannsen jojo@farm9.com
Thu, 14 Dec 2000 13:57:51 -0800


Thanks for the responses.  My first message was a little unclear...

Here is what I am doing in more detail:

On the client side (me), I have a windows machine, and I am uploading a
file:  "E:\test\my_file"

On the server, I am running Zope on Linux.  My upload form looks like this:

<dtml-var standard_html_header>
<h2><dtml-var title_or_id></h2>
<p>
<form method="post" action="Customize" enctype="multipart/form-data">
<input type="file" name="attached_file">
<input type=submit>
</form>
</p>
<dtml-var standard_html_footer>


So I use this form, and I think the file gets uploaded, though I'm not quite
sure where it goes.  The "Customize" DTML gets called when the form is
submitted, it looks like this:

<dtml-var standard_html_header>
<h2><dtml-var title_or_id> <dtml-var document_title></h2>
<p>
filename: <dtml-var "get_file_name(REQUEST)">
</p>
<dtml-var standard_html_footer>


And the "get_file_name" is a Python External Method, which looks like this:

def get_file_name(self,REQUEST):
        s = REQUEST.form['attached_file'].filename
        return s


Everything works great so far.

Now I want to do something with that file I just uploaded.

What is its name on the server?

The "filename" in the field I am pretty sure is NOT the name of the file on
the local system, since when I look at it, it says "E:\test\myfile" and this
is on a Linux system, so there is no such path.  That is the name file had
on my Windows system.

What sort of object is this "REQUEST.form['attached_file']"?   Is there some
way to find out this sort of thing when you have a Python object?  (I'm new
to Python)

Is that even the place to look to get the name of the file on the server
after it is uploaded?

That's why I mentioned the quote from that How-To (which the above is
basically a copy of):  "In you python external method you can now reference
REQUEST.form['attached_file'] as a normal file. You can perform things such
as read() on the object. "

This makes it seem like whatever is necessary, it is very easy, but there's
some detail that I am missing.  Maybe I just don't know what a "normal file"
is...

Regards,

JJ


Dieter Maurer wrote:

> Joh Johannsen writes:
>  > But it says: "In you python external method you can now reference
>  > REQUEST.form['attached_file'] as a normal file. You can
>  >                       perform things such as read() on the object. "
>  >
>  > Now in my Python external method, I can reference things like:
>  >
>  > REQUEST.form['attached_file'].filename
>  >
>  > and that is fine.
>  >
>  > But what is the syntax for actually reading the file?  From the above
>  > quote I thought it was as simple as
>  > x=REQUEST.form['attached_file'].read()  but that doesn't work...
> Please tell us, how it does not work (in fact, it should work):
>
>    Did you get an attribute error (read) or was the result wrong?
>
> You must use the 'enctype="multipart/form-data"' and
> 'method=post' form parameter to upload files. Did you do that?
>
> Dieter