-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I've set a limit for file uploads via zk.xml
When a user uploads a file which is bigger than the configured value, he get this message:
"the request was rejected because its size (666841914) exceeds the configured maximum (52428800)"
Is there a way to replace this message with something more user friendly?
Hi valmar,
Below is a work-around by override jq.alert:
<zk>
<script type="text/javascript">
var oldAlert = jq.alert;
jq.alert = function (msg, opts) {
if (!msg.indexOf('the request was rejected because its size'))
oldAlert(' new message ', opts); // use custom message here
else
oldAlert(msg, opts);
}
</script>
<fileupload label="Upload" maxsize="5" />
</zk>
Hm, how do I get the values for current and maximum file size?
I want to convert em to mb instead of bytes.
They are in the 'msg' variable,
please refer to the updated sample:
<zk>
<script type="text/javascript">
var oldAlert = jq.alert;
jq.alert = function (msg, opts) {
if (!msg.indexOf('the request was rejected because its size')) {
var oldMsg = msg;// get original number
msg = msg.replace('the request was rejected because its size (', '');
msg = msg.replace(') exceeds the configured maximum (', '_');
msg = msg.replace(')', '');
var v1 = msg.substring(0, msg.indexOf('_'));
var v2 = msg.substring(msg.indexOf('_')+1, msg.length);// calculate MB
var n1 = (parseInt(v1)/1024/ 1024).toFixed(2) + '-MB';
var n2 = (parseInt(v2)/1024/ 1024).toFixed(2) + '-MB';// replace original number with MB
oldMsg = oldMsg.replace(v1, n1);
oldMsg = oldMsg.replace(v2, n2);oldAlert(oldMsg, opts); // use custom message here
}
else
oldAlert(msg, opts);
}
</script>
<fileupload label="Upload" maxsize="5" />
</zk>
Awesome, thanks a lot!
if someone still need ... I made to files in format zip! It's works perfectly!
zul:
<fileupload id="flArquivo" label="Arquivo" width="100px" upload="true,maxsize=-1" />
java:
public void onUpload$flArquivo2(UploadEvent event) throws IOException {
int limitBytes = 31457280; // 30 Mb
int fileSizeBytes = event.getMedia().getStreamData().available();
if (fileSizeBytes <= limitBytes) {
// OK
} else {
// the request was rejected because its size (...) exceeds the configured maximum (...)
}
}
I hope it helps someone!
Asked: 2011-11-10 15:01:04 +0800
Seen: 533 times
Last updated: Aug 29 '16