1
0
-1

Hi,

 I want to set minimum size of file to be 20kb in my form. Since the upload document property has maximum size limit any way around to achieve this. I tried custom javascript but no luck? Can anyone help...

---------------------------------------------------------------------------

<script>

$('document.getElementById("upload_photo")').change( function()

{

const size =

(this.files[0].size / 1024 / 1024).toFixed(2);


if (size > 4 || size < 2) {

alert("File must be between the size of 2-4 MB");

} else {

}

});

</script>

-------------------------------------------------------------------------------

<script>
    Filevalidation = () => {
        const fi = document.getElementById('file');
        // Check if any file is selected.
        if (fi.files.length > 0) {
            for (const i = 0; i <= fi.files.length - 1; i++) {
  
                const fsize = fi.files.item(i).size;
                const file = Math.round((fsize / 1024));
                // The size of the file.
                if (file >= 4096) {
                    alert(
                      "File too Big, please select a file less than 4mb");
                } else if (file < 2048) {
                    alert(
                      "File too small, please select a file greater than 2mb");
                } else {
                    document.getElementById('size').innerHTML = '<b>'
                    + file + '</b> KB';
                }
            }
        }
    }
</script>

---------------------------------------------------------------------------------------------------------------

These are few codes which i tried but not working. What is syntax to get value from upload element i.e document.getElementById('file') is this right?

    CommentAdd your comment...

    1 answer

    1.  
      1
      0
      -1

      Hi, you can try using the FormUtil function in the JavaScript API to retrieve a form element value Javascript API#getValue(fieldId)

      1. Rushikesh Haral

        No it is not helpful. Could you be more specific pls.


      2. Anders

        Your question was "What is syntax to get value from upload element i.e document.getElementById('file') is this right?". Based on that link, you can use something like FormUtil.getField("file")

      3. Rushikesh Haral

        I tried this FormUtil.getField("file") but not getting output.

      CommentAdd your comment...