getting data from uploaded file

40 views
Skip to first unread message

raghu

unread,
Apr 17, 2008, 7:55:15 AM4/17/08
to Google App Engine

Hi,

I am trying to process an uploaded file and am using
'self.request.body_file'. It does work as file level object as
documented but it has additional information at the beginning and the
end as follows:

-----------------------------4186271753507
Content-Disposition: form-data; name="titles_file";
filename="ex_titles.txt"
Content-Type: text/plain

line1
line2

-----------------------------4186271753507--

What is the best way to get only the data portion of this? Should I
just ignore the fist few lines and last line (delimited by blank
line)?

The form is:

<form action="process" enctype="multipart/form-data" method="post">
file <input name="titles_file" type="file">
<input value="Submit" type="submit">
<input value="Clear the form" type="reset">
</form>


Thanks,
Raghu



Raffaele Sena

unread,
Apr 17, 2008, 12:36:47 PM4/17/08
to google-a...@googlegroups.com
what you got there is the full "content" section of the post request,
formatted as multipart-form/data

something like self.request.get('titles_file') seems to work for me
and returns just the content of the file I have uploaded

-- Raffaele

tj9991

unread,
Apr 17, 2008, 2:07:25 PM4/17/08
to Google App Engine
thefile = self.request.params['titles_file']
file_name = thefile.filename
file_value = thefile.value

For just the data, you'll want file_value

raghu

unread,
Apr 18, 2008, 7:00:04 AM4/18/08
to Google App Engine


On Apr 17, 2:07 pm, tj9991 <tslo...@gmail.com> wrote:
> thefile = self.request.params['titles_file']
> file_name = thefile.filename
> file_value = thefile.value
>
> For just the data, you'll want file_value

Thanks for both the responses. I found that the 'value' attribute
reads entire file as string while the 'file' attribute gives a file-
like object.
Reply all
Reply to author
Forward
0 new messages