1

i have migrated my application to wicket 6.14, and in the file upload field im trying to get the file name and the filesize using the below implementation

@Override
            public CharSequence getCallbackUrl() {
                CharSequence callBackUrl = super.getCallbackUrl();
                //File attribute of file input type is supported by certain browsers therefore conditionally returns the file size using js
                return callBackUrl +
                        "&filename=' + this.value + '&filesize=' + (function(undefined) {if($(\"<input type='file'>\").get(0).files !== undefined){ return $('#fileInput')[0].files[0].size}else{return 0;}})() + '";//"&filename=' + this.value + '";//
            }

But when i try to read the parameter value, it returns as this,value for the file name and the jquery function as the file size.

Request request = RequestCycle.get().getRequest();
                String filename = findFileName(request.getRequestParameters().getParameterValue("filename").toString());
                String fileSize = request.getRequestParameters().getParameterValue("filesize").toString();

How can i do this ?

  • There is no `getCallbackUrl()` method in `FileUploadField`. Please describe which class you're overriding and how you use it. Is it a behavior? – bernie Mar 19 '14 at 15:40

2 Answers2

0

It makes no sense to evaluate js to get the file size and read it afterwards from the request. At this time the file is already there and you can directly access it.

One hint to solution: Overwrite getAttributes() and add a new IAjaxCallListener. You can evaluate js there and put the file size in a hidden filed (or check the file size in getPrecondition() and return false if the file is to big).

mrak
  • 2,826
  • 21
  • 21
0

This answer might help for a cleaner wicket 6 way of doing it.

https://stackoverflow.com/a/23555297/463918

Community
  • 1
  • 1
Gorky
  • 1,393
  • 19
  • 21