aspose file tools*
The moose likes Flex and the fly likes Reading file size at client side using actionscript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Flex
Bookmark "Reading file size at client side using actionscript" Watch "Reading file size at client side using actionscript" New topic
Author

Reading file size at client side using actionscript

chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Hi everybody, I am Chaitanya, I want to upload files to server in my application and I want to restrict the file size say 1MB for an image, what I am thinking to do is run an actionscript function to check the file size at server side as soon as the user clicks submit button, I will force the client to install flash player plugin and enable java script.

Is the approach right? Thank you all in advance. Have a good day.


Love all, trust a few, do wrong to none.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

I think you people may say forcing the user to install a plugin for a silly upload is not the right way.

I say forcing the user is the right approach because instead of just uploading it to the server and checking the file size and breaking the request and asking him to upload the specified size file is somewhat time consuming. I think prevention is better than cure here.

What you say.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

How else do you use ActionScript without the user installing a version of Flash Player?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Paul Sturrock wrote:How else do you use Action Script without the user installing a version of Flash Player?


Provided the flash player is installed on the browser, or else the file size is calculated at the server. Moreover I already said I will force the user to install flash player. many sites wont run without JavaScript enabled or flash player installer, such as Orkut.

Moreover I wont suggest programmers to follow this method, I give up. Because if the client uses Google chrome browser the file path cannot be taken into java script, chrome will only return the file name, not the entire path, where as Mozilla and IE will return the entire path. So in chrome we cannot find the file size.

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Why do you need JavaScript to upload a file? JavaScript can't access the file system in the way you would need it to to unless you use browser specific code. ActionScript can, and should be cross browser. The normal mechanism though would be to check the size server side.
chaitanya karthikk
Ranch Hand

Joined: Sep 15, 2009
Posts: 800

Paul Sturrock wrote:Why do you need JavaScript to upload a file?


Hi Paul, you, misunderstood me. Actually the aim was to find the file size at the client side instead on finding the size at server and dropping the request if the size exceeds.

So somehow I should be able to enter the local drive and find the file size. Where javascript does not have such kind of abilities. So I supposed to choose action script. Action script can enter the local disk and find the file size. I have done this successfully from the browser.

Now what I have did his, read the html file input value from javascript and then call an appropriate actionscript's method to find the file size.

It went right on IE and mozilla, but didnt work properly in chrome, because the browser's sand box in not allowing javascript to read the html file's input value, its only giving the file name, where the entire path is required.

So I dropped the idea. Hope now you understand what I was trying to do.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Reading file size at client side using actionscript
 
Similar Threads
How To Create File on Server and access it on Client in 5 seconds of Interval
To learn Flex you start with scripting relative languages mxml, etc , or with learning the MENUes/FB
writing file on server side through applet
Password Protect a File or Directory
request.setParameter