1

how can I get file size at client side using actionscript and javascript

Thanks a lot

3 Answers 3

3

What you are looking for is the FileReference class.
Upon the user 'selecting' the file they wish to upload, the properties of that file is populated in the FileReference instance. Then accessing it, is simply to call:
fileRef.size()

Below is a code snippet to illustrate how to use FileReference class.

var fileRef:FileReference= new FileReference();
fileRef.browse([new FileFilter("Images", "*.jpg;*.gif;*.png")]);
fileRef.addEventListener(Event.SELECT, onFileSelected);

function onFileSelected(e:Event):void 
{
    trace("Size of file is:"+fileRef.size());
}
Sign up to request clarification or add additional context in comments.

Comments

1

You could try looking at the numerous flash based file upload methods and see if any give you back the actual file sizes of each file in the queue.

For example SWFUpload may have this functionality but I've not tested it.

Comments

-1

we can use this activeX code . But it will run only in few browsers

<html>
<head>
<script>
function getSize()
{
    var myFSO = new ActiveXObject("Scripting.FileSystemObject");
    var filepath = document.upload.file.value;
    var thefile = myFSO.getFile(filepath);
    var size = thefile.size;
    alert(size + " bytes");
}
</script>
</head>
<body>
<form name="upload">
<input type="file" name="file">
<input type="button" value="Size?" onClick="getSize();">
</form>
</body>
</html>

Check this URL How can you determine the file size in JavaScript? and also look at this URL http://devpro.it/FileReference/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.