Get started with filesize CDN

BSD-3-Clause licensed

Filesize.js is a lightweight library for displaying human-readable file sizes.

Tags:
  • file
  • filesize
  • size
  • readable
  • file system
  • bytes
  • diff

Stable version

Copied!

How to start using filesize CDN


<!DOCTYPE html>
<html>
<head>
    <title>Get started with filesize CDN - cdnhub.io</title>
    <script src="https://cdn.jsdelivr.net/npm/[email protected]/filesize.min.js"></script>
</head>
<body>
    <input type="file" id="fileInput" accept=".txt, .pdf">
    <button id="calculateButton">Calculate File Size</button>
    <p id="fileSizeResult"></p>

    <script>
        const fileInput = document.querySelector('#fileInput');
        const calculateButton = document.querySelector('#calculateButton');
        const fileSizeResult = document.querySelector('#fileSizeResult');

        calculateButton.addEventListener('click', () => {
            Filesize.load((filesizeApi) => {
                filesizeApi.loadFile(fileInput.files[0], (errors, fileSize) => {
                    if (errors) {
                        console.error('Error calculating file size:', errors);
                        return;
                    }
                    fileSizeResult.textContent = `File size: ${fileSize.size} bytes`;
                });
            });
        });
    </script>
</body>
</html>

All versions