Hello,
I have a weird problem with the file upload using Wicket.
I have a flex application on client side, and the user can upload some
files. Flex code is as simple as:
var fr:FileReference=new FileReference();
fr.addEventListener(Event.SELECT, function(e:Event):void {
var postVariables:URLVariables = new URLVariables;
postVariables.sessionid = "qwerttrew"; // some content here
var req:URLRequest = new URLRequest;
req.url = "" class="moz-txt-link-rfc2396E" href="http://localhost:8080/path/to/my/wicket/script/">"http://localhost:8080/path/to/my/wicket/script/";
req.method = URLRequestMethod.POST;
req.data = "">
fr.upload(req);
});
fr.addEventListener(HTTPStatusEvent.HTTP_STATUS,
function(e:HTTPStatusEvent):void {
if(e.status == 500) Alert.show("Une erreur a été rencontrée.
Veuillez réessayer!");
});
fr.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,
function(e:Event):void {
trace("upload complete");
});
fr.addEventListener(IOErrorEvent.IO_ERROR, function(e:Event):void
{
Alert.show("IOError: "+e);
});
fr.browse([new FileFilter("Fichiers autorisés",
"*.jpeg;*.jpg;*.png;*.swf")]);
On the wicket side, the code is:
Request request = getRequest();
if (!(request instanceof ServletWebRequest)) {
return;
}
ServletWebRequest swr = (ServletWebRequest) request;
HttpServletRequest hsr = swr.getHttpServletRequest();
if (!ServletFileUpload.isMultipartContent(hsr)) { return; }
MultipartServletWebRequest mswr;
try {
mswr = new MultipartServletWebRequest(hsr,
Bytes.megabytes(2));
} catch (FileUploadException e) {
e.printStackTrace();
throw new RuntimeException("Unable to get uploaded file!", e);
}
String sessionid = mswr.getParameter("sessionid");
Map map = mswr.getFiles();
for (Object o : map.keySet()) {
Object object = map.get(o);
if (object instanceof DiskFileItem) {
DiskFileItem dfi = (DiskFileItem) object;
File originalFile = dfi.getStoreLocation();
if (originalFile.length() <= 0) {
throw new IOException("No data were sent!"); //
<-- THROW THIS EXCEPTION WITH SOME FILES!!
}
File directory = new
File(AbstractApplication.get().getUploadFolder(), "logos");
directory = new File(directory, "temp");
directory.mkdirs();
File tempFile = new File(directory, sessionid + "_" +
tref + "." + FileUtils.getExt(dfi.getName()));
try {
if (!FileUtils.move(originalFile, tempFile)) {
throw new IOException("Unable to move file from
source to target!");
}
} catch (IOException e) {
throw new AbortWithHttpStatusException(500, false);
}
break;
}
}
Well, this works fine, except with some specific files. I've a file
"a.png", and it is always uploaded successfully. And I've a file
"b.png", which always fail!! (they are both very close on theire size,
several KB).
When it comes on the wicket code, the file length is 0 bytes... I'm not
very sure that it's a wicket problem, it may also be a Flex one... But
I never saw any thread on the Flex forums that speak about upload
problems...
Could anybody explain what is the problem?
Thank you very much!
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
|
- File upload weird problem Piller Sébastien
-