If you want to restrict the user from saving the record itself, if the file attachment in the form exceeds a specific limit like 1MB or 10MB or anything. The below javascript code using iol would help you achieve it.
At high level
the script will take over the handler on the save button when the page loads and checks the size of the file attached in the form, if it is more than 100K in this instance(which you can change in the code below from 100000 to the limit you want to set). it will show an alert and blocks the save action in other words it won't let user to save the record and if the size is within the accepted limit then the record will be saved.
NOTE: Alert message and any other details you can customize since you have the full control on the form now.
1. Create a code page in the application and copy the below code into it.
NOTE:
1. replace TABLE_DB_ID in the below code with dbid of the table where you are trying to restrict the file uploads based on the size. for instance, if table is file attachment then use dbid of that table.
2. replace files[0] with files[1] or files[2] if the form has more than one attachment. if not and form has only one file attachment then don't have to do anything.
var backupHandlers;
function checkFileSize() {
var reader = new FileReader();
reader.readAsDataURL(document.querySelector('input[type=file]').files[0]);
reader.addEventListener("load", function () {
//console.log($("#_fid_X")[0].fileSize);
//console.log(reader.result);
console.log(reader);
if(reader.result.length>100000){
alert("File size greater than 100k");
}else{
console.log("File size within the limits carry on with save.");
$("#saveButton").each(
function() {
var elementData = jQuery
._data(this), events = elementData.events;
//Restore default quickbase events
var onClickHandlers = events['click'];
//remove all the current click handlers on the save button
for (var idx = 0; idx < onClickHandlers.length; idx++) {
onClickHandlers.splice(0, 1);
}
//replace them with the handlers that quickbase configured when the page initially loaded
if(backupHandlers!=undefined){
for (var idx = 0; idx < backupHandlers.length; idx++) {
onClickHandlers.push(backupHandlers[idx]);
}
console.log("Total handlers left : "+ onClickHandlers.length);
}
//triggers save action
$("#saveButton").trigger("click");
});
}
}, false);
}
function alterSaveEventHandlers(){
console.log(DoSaveAdd);
$("#saveButton").on("click", checkFileSize);
$("#saveButton").each(function() {
var elementData = jQuery._data(this), events = elementData.events;
var onClickHandlers = events['click'];
// Only one handler. Nothing to change.
if (onClickHandlers.length == 1) {
return;
}
backupHandlers = new Array();
// onClickHandlers.splice(0, 0, onClickHandlers.pop());
for (var idx = 0; idx < onClickHandlers.length; idx++) {
backupHandlers.push(onClickHandlers[idx]);
onClickHandlers.splice(0, 1);
}
console.log("onClickHandlers : "+JSON.stringify(onClickHandlers));
});
console.log("updated click handlers on save button.");
}
(function() {
var querystring = document.location.search;
console.log("got into custom code section.");
if (/dlta=mog/i.test(querystring)) {
// GRID EDIT PAGE ========================================
console.log("You are on the Grid Edit Page");
} else if (/a=er/i.test(querystring) && /TABLE_DB_ID/i.test(window.parent.location) ) {
// EDIT RECORD PAGE ========================================
console.log("You are on the Edit Record Page");
alterSaveEventHandlers();
}else if (/a=API_GenAddRecordForm/i.test(querystring) && /TABLE_DB_ID/i.test(window.parent.location) ) {
// API_GenAddRecordForm PAGE ========================================
console.log("You are on the GenAddRecordForm Page!");
alterSaveEventHandlers();
} else if (/GenNewRecord/i.test(querystring)) {
// ADD RECORD PAGE ========================================
console.log("You are on the Add Record Page");
alterSaveEventHandlers();
} else if (/nwr/i.test(querystring)) {
// ADD RECORD PAGE ========================================
console.log("You are on the Add Record Page");
alterSaveEventHandlers();
} else if (/a=dr/i.test(querystring)) {
// DISPLAY RECORD PAGE
console.log("You are on the Display Record Page");
//$("img[qbu=module]").closest("td").css("background-color", "#FFFFFF");
setTimeout(requestForUpdates, 2000);
} else if (/a=q/i.test(querystring)) {
// REPORT PAGE ========================================
console.log("You are on the Report Listing Page");
} else if (/a=td/i.test(querystring)) {
//TABLE DASHBOARD PAGE ========================================
console.log("You are on the Table Dashboard Page");
} else if (/a=FinishEditRecord/i.test(querystring)) {
//FINISH EDIT RECORD PAGE ========================================
console.log("You are on the Finish Edit Record Page");
} else {
//OTHER PAGE ========================================
console.log("You are on the Some Other Page");
}
})();
Step 2:
follow the steps in the below url that helps you to load the above script file into the form
https://community.quickbase.com/quickbase/topics/create-parent-record-on-loading-of-child-form