I'm using playframework to build a web site. And I also use a rich editor named xheditor.
Xheditor support ajax-fileuploading, it needs the server side has a action which accepts "filedata" parameter which contains the upload file.
So I wrote a upload action:
public class Application extends Controller {
public static void upload(File filedata) {
// the filedata should not be null
renderText("{'err':'', 'msg':{'ur':'/uploaded/xxx.zip'}}");
}
}
It works fine in IE6, the filedata is not null and contains the correct data. But, if I use chrome or firefox, the filedata is null!!
I use firebug to monitor what the firebug submit, and found it submit such a header:
content-disposition
attachment; name="filedata"; filename="051111twdns.zip"
I think play has not handle this case correctly, so the parameter "filedata" is null.
In order to work with chrome and firefox, I modified that action:
public class Application extends Controller {
public static void upload(File filedata) {
if(filedata!=null) {
// ok, it's IE6
renderText("{'err':'', 'msg':{'ur':'/uploaded/xxx.zip'}}");
} else {
// it's chrome or firefox, the data is in request.body
File targetFile = new File("upload/test.zip");
IOUtils.copy(request.body, new FileOutputStream(targetFile));
}
}
}
This is worked in IE6, chrome and firefox now, BUT, only if the upload file is very small. E.g. less than 4K. If it's a little larger, e.g. 12K, the method "IOUtils.copy" will report "Read Error!", even the following code will report such error:
request.body.available()
request.body.read()
request.body.read(bytes)
Now, I don't know where is the problem, nor how to fix it. Hope someone give me some advices, thank you!