Get the data of uploaded file in javascript

Mar 3, 2019

Here is the most important article for us to check the file info before sending file to the server. So, in this tutorial, I will show you how to get file info before uploading in JavaScript.

If you tries to upload file that exceed the size limit, then the app must display a message, telling the user not to exceed the limit. Likewise, you can do many useful things with the size of the files, such as, convert the bytes to Kilobytes etc.

The File type

name – the filename

size – the size of the file in bytes

type – the MIME type for the file

File Name Using JavaScript:


File Size Using JavaScript:


File Type Using JavaScript:


Full Code:

<title>Get the data of uploaded file in javascript</title>
	<input type="file" id="fileName" onchange="getInfo()"/>
	<p id="fileinfo"></p>
		function getInfo(){
			var Size = document.getElementById('fileName').files[0].size;
			var Name = document.getElementById('fileName').files[0].name;
			var Type = document.getElementById('fileName').files[0].type;
			var fileinfo = 'File Name: '+Name+"<br/> File Size: "+Size+"<br/> File Type: "+Type;
			document.getElementById('fileinfo').innerHTML = fileinfo;

Copyright 2018. All rights are reserved