3 Replies Latest reply on May 8, 2008 12:38 PM by limitedwave777

    File upload

    limitedwave777
      I'm using this file upload script:
      http://weblog.cahlan.com/files/file_uploads/srcview/index.html
      - seems simple enough, works well. I'm used to working in html/php and AS 2.0 so this problem is throwing my for a spin. Does anyone know of how I might upload a file, and set some variable I can use to set my filename field equal to it? I've been trying for hours to access this variable and cannot find it. There are a few arrays in this mix and the best return I can get from anything is [object Object]. This is driving me crazy! Thanks.
        • 1. Re: File upload
          slaingod Level 1
          init:
          var imageTypes:FileFilter = new FileFilter("Videos (*.avi, *.wmv, *.mpg, *.mov, *.qt, *.flv, *.mpeg, *.mp4, *.m4v, *.ogm)", "*.avi; *.wmv; *.mpg; *.mov; *.qt; *.flv; *.mpeg; *.mp4; *.m4v; *.ogm");
          var allTypes:Array = new Array(imageTypes);
          fileRef = new FileReference();
          fileRef.addEventListener(Event.SELECT, selectHandler);
          fileRef.addEventListener(Event.CANCEL, cancelHandler);
          fileRef.addEventListener(Event.OPEN, startUpload);
          fileRef.addEventListener(Event.COMPLETE, completeHandler);
          fileRef.addEventListener(ProgressEvent.PROGRESS, uploadProgressHandler);
          fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA,uploadCompleteDataHandler);
          fileRef.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
          fileRef.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpStatusErrorHandler);
          fileRef.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
          fileRef.browse(allTypes);

          public function selectHandler(event:Event):void {
          // filename.text = fileRef.name;





          var params:URLVariables = new URLVariables();
          params.category = category.selection.id;

          var request:URLRequest = new URLRequest(Main.siteurl + '/api/upload')
          request.method = URLRequestMethod.POST;
          request.data = params;

          try
          {
          fileRef.upload(request);
          }
          catch (error:Error)
          {
          trace("Unable to upload file.");
          }
          }

          You should be able to get the name from the Fileref or you can just pass it in as another POST variable (from fileRef.name)
          • 2. Re: File upload
            limitedwave777 Level 1
            Wow, much appreciation for the reply. I'm not sure what parts of that code I can use. The goal is to assign the file name of the file selected to an extra textfield for submission to db. Ideally it would happen at the same time the file name selected appears in the listbox.

            Is this what I should be taking from that code:

            fileRef.addEventListener(Event.SELECT, selectHandler);

            public function selectHandler(event:Event):void {
            // filename.text = fileRef.name;
            }

            ...as in, I need to add a listener to the FileSelect, which, upon file selection calls the function selectHandler, which in turn assigns the value of .name(file name selected) to a textfield?

            Thanks.
            • 3. Re: File upload
              limitedwave777 Level 1
              Yeah, that totally worked. Tremendous thanks. While I'm at it, anyone know how to restart that entire app, or change states and refresh the data? Tried running init() at the end of everything, didn't work. Or maybe call a page refresh?