Uploaded image for project: 'ZK'
  1. ZK
  2. ZK-3272

Display file size message with the most readable unit

XMLWordPrintable

    • Icon: New Feature New Feature
    • Resolution: Done
    • Icon: Normal Normal
    • 8.5.2
    • 8.0.2
    • None
    • Security Level: Jimmy
    • None
    • ZK 8.0.3 S7, ZK 8.0.3 S9, ZK 8.0.3 S10, ZK 8.5.2 S1, ZK 8.5.2 S2

      When exceeding max size, the Dropupload always displays a file size in KB. The code below can convert a file size to the most readable size unit:

      <dropupload maxsize="5" detection="none" onUpload="" >
          <attribute name="content"><![CDATA[
              <b>Drop Here</b><br/>
              size < 5k
          ]]></attribute>
      </dropupload>
      
          zk.fmt.Text.stuff = zk.fmt.Text.format;
      
      	/**
      	 * Formatting a filesize depending on its value:
      	 * >= 1024 GB: 0.0 TB,
      	 * >= 1024 MB: 0.0 GB,
      	 * >= 1024 KB: 0.0 MB,
      	 * >= 1024 B : 0.0 KB,
      	 * else: bytes. Decimal point is determined by System language.
      	 */
          zk.fmt.Text.formatFileSize = function (bytes) {
              var divider = 1024;
      
              if(Math.abs(bytes) < divider) {
                  return bytes + msgzk.BYTES;
              }
      
              var units = [msgzk.KBYTES, msgzk.MBYTES, msgzk.GBYTES, msgzk.TBYTES]
              var unit = -1;
      
              do {
                  bytes /= divider;
                  ++unit;
              } while(Math.abs(bytes) >= divider && unit < units.length - 1);
      
              return +bytes.toFixed(1) + ' ' + units[unit];
          }
      
          zk.fmt.Text.format = function (msg) {
              if (msg == msgzul.UPLOAD_ERROR_EXCEED_MAXSIZE)
                  return zk.fmt.Text.stuff(msg, zk.fmt.Text.formatFileSize(arguments[3]), zk.fmt.Text.formatFileSize(arguments[4]));
              else
                  return zk.fmt.Text.stuff(arguments);
          }
      

            klyvechen klyvechen
            hawk hawk
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 1 day
                1d
                Remaining:
                Time Spent - 1 hour Remaining Estimate - 7 hours
                7h
                Logged:
                Time Spent - 1 hour Remaining Estimate - 7 hours
                1h