Advanced Script to Check Document Size before upload

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
RentProperty
Posts: 345
Joined: Mon Nov 12, 2012 9:08 pm
Location: South Africa

Advanced Script to Check Document Size before upload

Post by RentProperty »

Hi guys,

Just thought we'd share this Scriptlet we got working for checking document size before it is uploaded to AwareIM. I.e. the size is checked when the document is selected.

You can put it in the Advance Initialization Script of the Form and change the size and message. Works like a charm for us:

Code: Select all

for (var i = 0; i < widgets.length; ++i) {
    if (widgets[i].type == "upload") {
        widgets[i].config.select = function onSelect(e) {
            $.each(e.files, function (index, value) {
                if (value.size > 5000000) {
                    e.preventDefault();
                    alert("Document too large (>5mb) - please resize the document and try again.");
                }
            });
        };
    }
}
Hein Hanekom & Werner Hanekom
Sinov8.net
AwareIM Version 5.9 | 6.0 | 7.0 | 7.1 (Windows EC2 R2012 & MySQL)
kklosson
Posts: 1628
Joined: Sun Nov 23, 2008 3:19 pm
Location: Virginia

Re: Advanced Script to Check Document Size before upload

Post by kklosson »

Thanks for sharing. I believe I can say for a fact that my server has been brought down several times by one or more users uploading a large document. Everyone should deploy this script where you have document uploads. Since deploying a similar solution, I have had no problems.
V8.8
MySQL, AWS EC2, S3
PDFtk Toolkit
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Re: Advanced Script to Check Document Size before upload

Post by tford »

if (value.size > 5000000)
Is it possible to have value.size > look at an AwareIM SystemSettings attribute rather than a hard coded value?
Tom - V8.8 build 3137 - MySql / PostGres
crisg0112
Posts: 395
Joined: Fri Jan 31, 2014 3:45 am
Location: Melbourne, Australia

Re: Advanced Script to Check Document Size before upload

Post by crisg0112 »

Hi,

would this work if you have the attribute set as 'use multi-file upload for document attribute'??

Thanks
Thanks in advance!

Cris
MSSQL 2008R2, Aware 7 b2146, IE11, , Firefox 35.0.1, Windows 8 Bootstrap theme
RentProperty
Posts: 345
Joined: Mon Nov 12, 2012 9:08 pm
Location: South Africa

Re: Advanced Script to Check Document Size before upload

Post by RentProperty »

Hi Tom & Chris, Not sure. Haven't played around with different implementations yet. Things are bit crazy at the moment.

But the default implementation definitely works for a single document.
Hein Hanekom & Werner Hanekom
Sinov8.net
AwareIM Version 5.9 | 6.0 | 7.0 | 7.1 (Windows EC2 R2012 & MySQL)
Post Reply