I am looking for the best way to upload the XML file to the GAE DataStore from the web page. The XML will be later parsed and modified wia the web interface. So far I am using the HTMLform
with file typeinput
:
<form enctype="multipart/form-data" action="update" method="post" >
<input type="file" name="myfile" />
<input type="submit" />
</form>
In the servlet class I use the for loop to read the data into String
:
InputStream input = req.getInputStream();
StringBuffer sb = new StringBuffer("");
int c = -1;
while ( (c = input.read() ) != -1 )
{
char ch = (char) c;
sb.append( ch );
}
Then I check if the DataStore contains the entity with application hardcoded key value and if not I create a new entity and upload the XML into Text
(com.google.appengine.api.datastore.Text
), otherwise I create a new entity and put the file there. Is that something you can call the good approach?
Regards, STeN
If you use a html form with type="file"
field, then browser will upload the file via http POST with a multipart/form-data
content type.
See AppEngine docs on how to handle properly multipart content data.