File Upload information in $req.data

4 views
Skip to first unread message

tsaixingwei

unread,
Feb 2, 2011, 12:59:51 AM2/2/11
to MynaJS-General
In the documentation it was mentioned that the file upload information
would be available as

$req.data.parameter_name ={
diskItem: org.apache.commons.fileupload.disk.DiskFileItem,
stats:{
fieldName:String, name of field in form,
fileName:String, name of file on client side,
contentType:String, mime type,
isInMemory:boolean, true if file contents are in memory,
sizeInBytes:int, size in bytes,
diskLocation:String, the current location of the uploaded file
}
}


However, in a simple test, the $req.data.parameter_name returns not an
object structure like the above but instead it returns just a simple
string which is the fileName. So am I doing it right or is the above
object structure not implemented yet?

My test code is one of the examples provided in the documentation but
modified to contain a file input html element:

<form method="post">
First Name: <input name="first_name"><br>
Favorite colors:<br>
<input type="checkbox" name="favorite_colors" value="red">Red
<input type="checkbox" name="favorite_colors" value="orange">Orange
<input type="checkbox" name="favorite_colors" value="yellow">Yellow
<input type="checkbox" name="favorite_colors" value="green">Green
<input type="checkbox" name="favorite_colors" value="blue">Blue
<input type="checkbox" name="favorite_colors" value="indigo">Indigo
<input type="checkbox" name="favorite_colors" value="violet">Violet
<p>

File Input: <br>
<input type="file" name="fileupload1"><br/>

Some Json Code:<br>
<textarea cols="60" rows="10" name="json">
{
"array":[
"thing1",
"thing2"],
"number":12,
"string":"some string",
"sub_object":{
"number":12,
"string":"some string"
}
}
</textarea><p>

More Json Code with the same name:<br>
<textarea cols="60" rows="3" name="json">
{
"phrase":"Dude, where's my car?"
}
</textarea><p>

A Cross Site Scripting hack:<br>
<textarea name="xss">';alert(String.fromCharCode(88,83,83))//\';

alert(String.fromCharCode(88,83,83))//";alert(String.fromCharCode(88,83,83))//
\";
alert(String.fromCharCode(88,83,83))//--></SCRIPT>">'>
<SCRIPT>alert(String.fromCharCode(88,83,83))</SCRIPT></textarea>
<p>
Display: <select name="dump_data">
<option value="filtered">$req.data</option>
<option value="raw">$req.rawData</option>
</select><p>
<button type="submit">submit</button>
</form>


<@if $req.data.dump_data == "filtered">
<%=Myna.dump($req.data,"$req.data", 6)%>
<@elseif $req.data.dump_data == "raw">
<%=Myna.dump($req.rawData,"$req.rawData", 6)%>
</@if>

<@if $req.data.fileupload1 != null>
Uploaded File:<br>
Type of fileupload1: <%= typeof $req.data.fileupload1 %> <br/>
<%=Myna.dump($req.data.fileupload1,"$req.data.fileupload1", 6)%>
</@if>


tsaixingwei

unread,
Feb 2, 2011, 12:59:52 AM2/2/11
to MynaJS-General

Mark Porter

unread,
Feb 2, 2011, 10:23:35 AM2/2/11
to mynajs-...@googlegroups.com
This is because the form tag requires an [ enctype="multipart/form-data" ] when uploading files. This is not a Myna requirement but rather an HTML requirement. 

Have a look in the /examples/index.ejs folder, particularly the "File Uploads" example for a demo of multiple file uploads with progress output

----------------------------------------------------------
Mark Porter

Myna JavaScript Application Server
Easy web development with server-side JavaScript
http://www.mynajs.org


--
You received this message because you are subscribed to the Google Groups "MynaJS-General" group.
To post to this group, send email to mynajs-...@googlegroups.com.
To unsubscribe from this group, send email to mynajs-genera...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mynajs-general?hl=en.


Reply all
Reply to author
Forward
0 new messages