I am using jQuery 1.7.1.
After an image loads in the browser window, I want to retrieve its total byte size. Is there an object name / value for that?
I am using jQuery 1.7.1.
After an image loads in the browser window, I want to retrieve its total byte size. Is there an object name / value for that?
No, there is no way you can get the image size using jQuery or pure JavaScript. The only way is to get it from server side using ajax.
You can get the image url send it to a service or server side page and have the page or service return the image size.
**here is the jQuery Code to get image size and type with validations ** you can use this code inside the function in your jQuery file
if (window.File && window.FileReader && window.FileList && window.Blob)
{
var pic_size = $('#profile_pic')[0].files[0].size;//get file size
var pic_type = $('#profile_pic')[0].files[0].type;
var extension = pic_type.split('/').pop().toUpperCase();
if (extension!="PNG" && extension!="JPG" && extension!="GIF" && extension!="JPEG" || pic_size>=2048000)
{
alert ("Please Select PNG,JPG,GIF,JPEG Image Only and File Size not Greater than 2MB");
$( "#profile_pic" ).focus()
return false;
}
}
Try this there is javascript code
$("#file_id")[0].files[0].size
You can get file size by below
$("#selector")[0].files[0].size
And Also You can get file format by below
$("#selector")[0].files[0].type
Also if you want validation like file size is not more than 2 MB than you can try by this
var mS_totalBytes = this.files[0].size;
var mS_size = Math.floor(mS_totalBytes/1024000); // its on MB
use if else condition based on your requirements like below
var mS_totalBytes = this.files[0].size;
var _size = Math.floor(mS_totalBytes/1024000); // in MB
//alert(mS_size);
if(mS_size >= 1){
jQuery(".ExportAndroidAsset").prop('disabled', true);
alert("MAximum File Size is 1MB");
jQuery(".pxel_Bar").css("width","1%");
jQuery(".pxel_Progress").hide();
jQuery(".tab-pane .output label").show();
jQuery('input[name=imagefile]').val('');
}
else{
jQuery(".ExportAndroidAsset").prop('disabled', false);
jQuery(".pxel_Progress").show();
jQuery(".tab-pane .output label").hide();
}
I don't think this is possible. You'll probably need a server-side language.