I use playframework to create a website. And I also use a rich editor called xheditor .
Xheditor supports ajax-fileupload download, it needs a server side that accepts the "filedata" parameter, which contains the download file.
So, I wrote an action to load:
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, filedata is not null and contains the correct data. But if I use chrome or firefox, filedata is null !!
I use firebug to monitor what Firebug represents, and found that it sends such a header:
content-disposition attachment; name="filedata"; filename="051111twdns.zip"
I think the game does not handle this case correctly, so the "filedata" parameter is null.
To work with chrome and firefox, I changed this action:
public class Application extends Controller { public static void upload(File filedata) { if(filedata!=null) { // ok, it IE6 renderText("{'err':'', 'msg':{'ur':'/uploaded/xxx.zip'}}"); } else { // it chrome or firefox, the data is in request.body File targetFile = new File("upload/test.zip"); IOUtils.copy(request.body, new FileOutputStream(targetFile)); } } }
Now it works in IE6, chrome and firefox, BUT only if the download file is very small. For example. less than 4K. If it is slightly larger, for example, 12K, the method "IOUtils.copy" will report "Read Error!", Even the following code will report such an error:
request.body.available() request.body.read() request.body.read(bytes)
firefox google-chrome internet-explorer file-upload playframework
Freewind
source share