0 Replies Latest reply on Dec 9, 2010 11:31 AM by Handycam

    How can I limit the size of a file upload?

    Handycam Level 1

      I am uploading a file using a file reference using the code below.  I want to  limit the file size (bytes) of the uploaded file to 100k, so that a huge file won't crash the browser or my SWF.


      What's the best place in the following process to test this, and actually prevent the large file from being loaded?  Is that even possible?



      private function uploadImageBtn_clickHandler() : void {
           var arr:Array = [];
           arr.push(new FileFilter("Images", "*.gif;*.jpeg;*.jpg;*.png"));
      private function fileReference_select(evt:Event):void {
      private function fileReference_complete(event:Event):void {
           var loader:Loader = new Loader();
           loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loader_complete);
      public function loader_complete (event:Event) : void {
           trace("Loader info = "+event.currentTarget.bytesLoaded); // file size in bytes
           var sourceBMP:Bitmap = event.currentTarget.loader.content as Bitmap;
           bgImage.source = sourceBMP;