Skip to content
Rishan Solutions
Rishan Solutions
  • PowerApps
  • SharePoint online
    • Uncategorized
    • Uncategorized
  • PowerAutomate
Rishan Solutions
Latest Posts
  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025 June 24, 2025
  • Recursive Queries in T-SQL May 7, 2025
  • Generating Test Data with CROSS JOIN May 7, 2025
  • Working with Hierarchical Data May 7, 2025
  • Using TRY_CAST vs CAST May 7, 2025
  • Dynamic SQL Execution with sp_executesql May 7, 2025

Reading file metadata using jQuery

Posted on April 2, 2025April 2, 2025 by Zubair Shaik

Loading

Reading File Metadata Using jQuery – A Comprehensive Guide

Table of Contents

1️⃣ Introduction to File Metadata
2️⃣ Why Read File Metadata?
3️⃣ Understanding the File API in JavaScript
4️⃣ Setting Up the Development Environment
5️⃣ Creating the HTML Structure for File Upload
6️⃣ Implementing jQuery to Read File Metadata
7️⃣ Extracting Metadata (File Name, Size, Type, and Last Modified Date)
8️⃣ Displaying File Metadata on the Webpage
9️⃣ Validating File Metadata Before Upload
🔟 Handling Multiple File Selection
1️⃣1️⃣ Extracting Image Metadata (Width, Height, and EXIF Data)
1️⃣2️⃣ Working with Audio and Video File Metadata
1️⃣3️⃣ Enhancing UI with CSS and Animations
1️⃣4️⃣ Secure Handling of File Metadata
1️⃣5️⃣ Debugging Common Issues
1️⃣6️⃣ Conclusion


1️⃣ Introduction to File Metadata

What is File Metadata?

Metadata is information about a file, such as:

  • 📄 File Name – The name of the file
  • 🗂 File Type – MIME type (e.g., image/png, video/mp4)
  • 📏 File Size – Size in bytes or MB
  • 📆 Last Modified Date – Timestamp of last modification

Example:
For an image file (photo.jpg), metadata may include:
✔ File Name: photo.jpg
✔ File Type: image/jpeg
✔ File Size: 2.5 MB
✔ Last Modified: March 20, 2024, 10:30 AM


2️⃣ Why Read File Metadata?

✔ Validate files before uploading (e.g., restrict file size, type)
✔ Provide real-time file information to users
✔ Enhance file preview features
✔ Improve security measures before sending files to the server


3️⃣ Understanding the File API in JavaScript

The JavaScript File API allows web applications to:

  • Access file properties
  • Read file contents
  • Extract metadata
  • Display file previews

Key Methods in the File API

MethodDescription
File.nameGets the file name
File.sizeGets the file size (in bytes)
File.typeGets the MIME type
File.lastModifiedGets last modified date
URL.createObjectURL(file)Creates a URL for file preview

4️⃣ Setting Up the Development Environment

📂 Project Structure:

  • 📜 index.html (Frontend UI)
  • 📜 style.css (Styling)
  • 📜 script.js (jQuery logic)

Include jQuery in index.html

<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

5️⃣ Creating the HTML Structure for File Upload

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>File Metadata Reader</title>
    <link rel="stylesheet" href="style.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>

    <div class="container">
        <h2>Select a File to Read Metadata</h2>
        <input type="file" id="fileInput">
        <div id="fileMetadata"></div>
    </div>

    <script src="script.js"></script>
</body>
</html>

6️⃣ Implementing jQuery to Read File Metadata

Listening for File Selection in script.js

$(document).ready(function(){
    $("#fileInput").on("change", function(event){
        let file = event.target.files[0]; // Get the first selected file
        if (file) {
            displayFileMetadata(file);
        }
    });
});

7️⃣ Extracting Metadata (File Name, Size, Type, and Last Modified Date)

function displayFileMetadata(file) {
    let metadataHtml = `
        <p><strong>File Name:</strong> ${file.name}</p>
        <p><strong>File Type:</strong> ${file.type}</p>
        <p><strong>File Size:</strong> ${(file.size / 1024 / 1024).toFixed(2)} MB</p>
        <p><strong>Last Modified:</strong> ${new Date(file.lastModified).toLocaleString()}</p>
    `;

    $("#fileMetadata").html(metadataHtml);
}

8️⃣ Displaying File Metadata on the Webpage

✔ Selected file’s metadata will now be displayed dynamically inside #fileMetadata.


9️⃣ Validating File Metadata Before Upload

function validateFile(file) {
    let allowedTypes = ["image/jpeg", "image/png", "application/pdf"];
    let maxSize = 5 * 1024 * 1024; // 5MB

    if (!allowedTypes.includes(file.type)) {
        alert("Invalid file type: " + file.name);
        return false;
    }

    if (file.size > maxSize) {
        alert("File too large: " + file.name);
        return false;
    }

    return true;
}

🔟 Handling Multiple File Selection

$("#fileInput").on("change", function(event){
    let files = event.target.files;
    let output = "";

    for (let file of files) {
        output += `
            <p><strong>File Name:</strong> ${file.name}</p>
            <p><strong>File Type:</strong> ${file.type}</p>
            <p><strong>File Size:</strong> ${(file.size / 1024 / 1024).toFixed(2)} MB</p>
            <p><strong>Last Modified:</strong> ${new Date(file.lastModified).toLocaleString()}</p>
            <hr>
        `;
    }

    $("#fileMetadata").html(output);
});

1️⃣1️⃣ Extracting Image Metadata (Width, Height, and EXIF Data)

function getImageMetadata(file) {
    let img = new Image();
    img.src = URL.createObjectURL(file);

    img.onload = function() {
        $("#fileMetadata").append(`
            <p><strong>Image Width:</strong> ${img.width}px</p>
            <p><strong>Image Height:</strong> ${img.height}px</p>
        `);
    };
}

1️⃣2️⃣ Working with Audio and Video File Metadata

function getMediaMetadata(file) {
    let media = document.createElement("video");
    media.src = URL.createObjectURL(file);

    media.onloadedmetadata = function() {
        $("#fileMetadata").append(`
            <p><strong>Duration:</strong> ${media.duration.toFixed(2)} seconds</p>
        `);
    };
}

1️⃣3️⃣ Enhancing UI with CSS and Animations

.container {
    text-align: center;
    margin-top: 20px;
}

input {
    margin-bottom: 20px;
}

#fileMetadata {
    background: #f4f4f4;
    padding: 10px;
    border-radius: 5px;
    max-width: 500px;
    margin: auto;
}

1️⃣4️⃣ Secure Handling of File Metadata

✔ Prevent XSS Attacks – Avoid inserting metadata directly into HTML
✔ Sanitize File Names – Escape special characters
✔ Restrict File Access – Use secure server-side validation


1️⃣5️⃣ Debugging Common Issues

✔ File API not working? – Ensure browser supports it
✔ Metadata not displaying? – Use console.log(file) to inspect
✔ File size incorrect? – Convert bytes to MB correctly


🎯 We successfully implemented file metadata reading using jQuery and JavaScript File API! 🚀

✅ Supports name, type, size, last modified date
✅ Works with multiple file selection
✅ Handles image, audio, and video metadata

🔹 Next Steps: Integrate file previews and server-side validation!

Posted Under jQueryAsynchronous File Metadata Retrieval Audio File Metadata Audio Metadata Processing Browser File Handling Client-Side File Handling Data Processing in Web Applications Extracting Video Metadata File API Compatibility File Drag and Drop File Information Analysis File Information Display File Information Extraction File Input Handling File Management in JavaScript. File Metadata File Metadata Debugging File Metadata Extraction File Metadata Processing File Name Retrieval File Preview with Metadata File Security Best Practices File Size Extraction file size validation File Type Detection File Type Validation File Upload Debugging File Upload Metadata File Upload Restrictions File Upload System File Upload UX File Validation Frontend File Processing Handling Large Files html5 file api HTML5 File Input Image Metadata Extraction JavaScript File API JavaScript File Handling JavaScript file validation jQuery event handling jQuery File API jQuery File Handling Last Modified Date Metadata Display UI Multiple File Selection Read File Properties Reading Document Metadata Reading EXIF Data Reading File Attributes Reading Image Metadata Real-Time File Processing Secure File Processing Secure Metadata Extraction Video File Details Web Development File Management Web File Processing

Post navigation

Modifying state directly instead of using setState()
Setting state inside render() leading to infinite loop

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Agentic AI: The Dawn of Autonomous Intelligence Revolutionizing 2025
  • Recursive Queries in T-SQL
  • Generating Test Data with CROSS JOIN
  • Working with Hierarchical Data
  • Using TRY_CAST vs CAST

Recent Comments

  1. Michael Francis on Search , Filter and Lookup in power apps
  2. A WordPress Commenter on Hello world!

Archives

  • June 2025
  • May 2025
  • April 2025
  • March 2025
  • February 2025
  • March 2024
  • November 2023
  • October 2023
  • September 2023
  • August 2023
  • June 2023
  • May 2023
  • April 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • January 2022

Categories

  • Active Directory
  • AI
  • AngularJS
  • Blockchain
  • Button
  • Buttons
  • Choice Column
  • Cloud
  • Cloud Computing
  • Data Science
  • Distribution List
  • DotNet
  • Dynamics365
  • Excel Desktop
  • Extended Reality (XR) – AR, VR, MR
  • Gallery
  • Icons
  • IoT
  • Java
  • Java Script
  • jQuery
  • Microsoft Teams
  • ML
  • MS Excel
  • MS Office 365
  • MS Word
  • Office 365
  • Outlook
  • PDF File
  • PNP PowerShell
  • Power BI
  • Power Pages
  • Power Platform
  • Power Virtual Agent
  • PowerApps
  • PowerAutomate
  • PowerPoint Desktop
  • PVA
  • Python
  • Quantum Computing
  • Radio button
  • ReactJS
  • Security Groups
  • SharePoint Document library
  • SharePoint online
  • SharePoint onpremise
  • SQL
  • SQL Server
  • Template
  • Uncategorized
  • Variable
  • Visio
  • Visual Studio code
  • Windows
© Rishan Solutions 2025 | Designed by PixaHive.com.
  • Rishan Solutions