I am allowing my users to upload mp3 files just so I can read the metadata and extract the Song Title and Singer Name.
At the moment I am uploading the file and using getId to read the meta data. The upload of course takes a lot of resources and bandwidth. And it seems kind of wasteful to upload the mp3s since all I need are 2 pieces of information and I won't even be doing anything with the file itself. So I delete it afterwards.
Is it possible to get these 2 pieces of information on the client side without copying the file to my server?
you can only do this in HTML5 compliant browsers that implemented the FileReader interface (Firefox, Chrome, IE10, Safari 5.1+, not sure about Opera).
You basically use FileReader to get the contents of your file into memory and then manually scan (in client-side javascript) for the MP3 tags you want.
You can only get information from a client-side file by either uploading it and processing it on the server (which you don't want to do), or distributing a client that will process the file on the client-side and upload just the pertinent information. Option 2 requires you develop (or co-opt) a client application, and distribute it.
Like this you mean: Working demo http://jsfiddle.net/9pfLJ/
Good link: http://jquerybyexample.blogspot.com/2012/03/how-to-check-file-size-before-uploading.html
http://www.aibn.com/help/Learn/mimetypes.html
Hope it helps your cause :)
, rest feel free to play around with the demo.
P.S. - in the demo it will alert the file name as well.
code
$(document).ready(function() {
$("#flUpload").change(function ()
{
var iSize = ($("#flUpload")[0].files[0].size / 1024);
alert("Name of file ===> " + $("#flUpload")[0].files[0].name);
if (iSize / 1024 > 1)
{
if (((iSize / 1024) / 1024) > 1)
{
iSize = (Math.round(((iSize / 1024) / 1024) * 100) / 100);
$("#lblSize").html( iSize + "Gb");
}
else
{
iSize = (Math.round((iSize / 1024) * 100) / 100)
$("#lblSize").html( iSize + "Mb");
}
}
else
{
iSize = (Math.round(iSize * 100) / 100)
$("#lblSize").html( iSize + "kb");
}
});
});