Reputation: 230038
I wrote this simple Play-uploadify demo.
I want to an upload button that automatically upload an image each time its pressed.
For some reason, only the first time the button is pressed, I get an upload. After the button has been pressed once, further presses do not cause anything unless I "cancel" the previous uploads.
(I don't understand the meaning of canceling an upload with auto
mode. Perhaps the problem is that my downloads never "complete" in some sense?)
Here is my action method:
public static void upload(File file, long userId){
System.out.println("Uploaded file name " + file.getName() +
" by user " + userId);
}
And the call to uploadify:
$(function() {
$("#uploader").uploadify({
uploader : '/public/libraries/uploadify/uploadify.swf',
script : '/Application/upload',
cancelImg : '/public/libraries/uploadify/cancel.png',
folder : '/uploads',
fileExt : '*.jpg;*.gif;*.png',
fileDesc : 'Image Files',
fileDataName: 'file',
scriptData: {userId: 123},
auto: true
});
});
Also, the upload never seems to complete - when I add an onComplete
handler, it does't fire.
Upvotes: 1
Views: 465
Reputation: 230038
The problem was that I was not returning a HTTP 200
status code, because I didn't call any render method or return a value at the end of my action method.
Adding renderText("OK");
resolved my problem.
ok();
is a neater way of resolving it.
Upvotes: 1
Reputation: 1831
try to change it to
script : '/application/upload',
(notice the lowercase a in application... play always generates lowercase urls when you use the default route.)
as for only being able to upload one file at a time:
have you tested the upload in dev or production mode? in dev mode, the amount of threads available for processing is one, so it will block as soon as you want to upload a second file at the same moment
Upvotes: 0