Basically you cannot use "/apath/" + file.getName() because file.getName() returns a full path and not a name (this is coming from the commons file_upload lib), so for example on windows, this will give you a path of '/apath/c:/whatever/myfile.jpg' which is not valid and gives you the exception you had.
I have fixed this so that you can give the path like this:
- Code: Select all
plugins.file.streamFilesToServer(file,'/sub1/sub2/', callbackMethod);
For example, this now works in web client:
- Code: Select all
function onActionFile(event) {
plugins.file.showFileOpenDialog(sendFile);
}
function sendFile(files) {
if (files) {
// note that files here is actually an array, so you can do this:
for (var i = 0; i < files.length; i++) {
var file = files[i];
plugins.file.streamFilesToServer(file,'/sub1/sub2/', uploadFinished);
}
// or simply this:
plugins.file.streamFilesToServer(files,'/sub1/sub2/', uploadFinished);
}
}
function uploadFinished(result, ex) {
if (ex) {
application.output(ex);
} else {
application.output(result.getAbsolutePath());
}
}
In this example, '/sub1/sub2/' will automatically be created on the server in the upload folder declared (or by default in /application_server/server/webapps/ROOT/uploads/), and the files will be put inside this location on the server.
You can also change the name of the file on the server if you prefer, by giving it a full path (with the new file name included), so:
- Code: Select all
plugins.file.streamFilesToServer(file,'/sub1/sub2/newFileName.jpg', callbackMethod);
will also work.
Try it with the attached plugin jar attached.
Johan: a patch follows