Limit Document upload sizes Version 7 / 7.1

If you have questions or if you want to share your opinion about Aware IM post your message on this forum
Post Reply
rob_h7
Posts: 85
Joined: Mon Jan 25, 2010 3:52 am

Limit Document upload sizes Version 7 / 7.1

Post by rob_h7 »

On version 6, we used to have Business Object rules in order to stop people uploading large documents which would crash the system. However, as per Support, with version 7 - 7.1, these no longer work.

At some point in a future build, we'll be able to limit file size uploads in the config, however for now, the below can be used if anyone is interested.

For a single Doc attribute on a form - use the following Advanced Script:

Code: Select all

var oldUpload = config.config.upload;
config.config.upload = function (e)
{
 for (var i = 0; i < e.files.length; ++ i)
 {
 if (e.files[i].size > 10000 /* specify desired size in bytes here */)
 {
 alert ("file " + e.files[i].name + "." + e.files[i].extension + " is too large");
 e.preventDefault ();
 return;
 }
 }

 oldUpload.call (this, e);
}
For the multiple file upload there is no solution other than modifying Aware IM code. You need to add similar code to the file AwareIM/Tomcat/webapps/AwareIM/aware_kendo/mfu.js

You need to change the following bit of code

Code: Select all

var wc = {
			async: {
				saveUrl: AwareApp.m_serverUrl + "request.awmu?",
				removeUrl: AwareApp.m_serverUrl + "request.awmu?"
			},
			upload: function (e) {
				me.onUploadRemove (e, false);
			},
			remove: function (e) {
				me.onUploadRemove (e, true);
			},
			error: function (e) {
				me.onError (e);
			}
		};


to this:

Code: Select all

var wc = {
			async: {
				saveUrl: AwareApp.m_serverUrl + "request.awmu?",
				removeUrl: AwareApp.m_serverUrl + "request.awmu?"
			},
			upload: function (e) {
 if (true)
 {
 for (var i = 0; i < e.files.length; ++ i)
 {
 if (e.files[i].size > 10000 /* specify desired size in bytes here */)
 {
 alert ("file " + e.files[i].name + "." + e.files[i].extension + " is too large");
 e.preventDefault ();
 return;
 }
 }
 }
				me.onUploadRemove (e, false);
			},
			remove: function (e) {
				me.onUploadRemove (e, true);
			},
			error: function (e) {
				me.onError (e);
			}
		};
This will apply to every multi-file upload. If you want to do it for a specific process or document attribute you need to analyse me.m_config which defines specific parameters of MFU and change this bit:

Code: Select all

 if (true)
 {
 for (var i = 0; i < e.files.length; ++ i)
 {
to

Code: Select all

if (condition when to perform validation)
 {
 for (var i = 0; i < e.files.length; ++ i)
 {
I've got it applying to all multi uploads, I didn't get into the me.m_config file.
Rob . Aware 8.4 (build 2718), Developer Edition, using Linux, MYSQL
weblike
Posts: 1165
Joined: Sun Dec 02, 2012 12:00 pm
Location: Europe

Re: Limit Document upload sizes Version 7 / 7.1

Post by weblike »

Hi,

Why don't you simply use FILE_SIZE function?

If FILE_SIZE(BO.Document)>4194304 Then
REPORT ERROR 'The Size of the file is too big'
Thx,
George
________________________________
Developer Edition
AwareIM: v8.5, build 2824
OS: Windows Server 2012
DB: MySql 5.6.42
rob_h7
Posts: 85
Joined: Mon Jan 25, 2010 3:52 am

Re: Limit Document upload sizes Version 7 / 7.1

Post by rob_h7 »

We did, but I think that checks once the file has finished uploading. We had a user attempt a 140MB MP4 file, which killed the server before the rule had a chance to do anything.
Rob . Aware 8.4 (build 2718), Developer Edition, using Linux, MYSQL
pureist
Posts: 427
Joined: Sun Jan 24, 2016 10:00 pm

Re: Limit Document upload sizes Version 7 / 7.1

Post by pureist »

for anyone reading and interested in this issue in future, also read:
http://www.awareim.com/forum/viewtopic. ... 027#p40027
Post Reply