21
Sep
07

Uploading files in Flex using the FileReference class

In an earlier example we looked at “Downloading files in Flex using the FileReference class“, but It looks like we haven’t ever looked at file uploads.
The following example shows how you can use the FileReference class’s browse() method to allow users to select and upload a single file to a Web server.

If you want to allow users to upload multiple files at once, you would use the FileReferenceList class instead of FileReference.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/09/21/uploading-files-in-flex-using-the-filereference-class/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        creationComplete="init();">

    <mx:Script>
        <![CDATA[
            private var fileRef:FileReference;

            private const FILE_UPLOAD_URL:String = "http://www.YOUR-WEBSITE-HERE.com/fileref/uploader.cfm";

            private function init():void {
                fileRef = new FileReference();
                fileRef.addEventListener(Event.SELECT, fileRef_select);
                fileRef.addEventListener(ProgressEvent.PROGRESS, fileRef_progress);
                fileRef.addEventListener(Event.COMPLETE, fileRef_complete);
            }

            private function browseAndUpload():void {
                fileRef.browse();
                message.text = "";
            }

            private function fileRef_select(evt:Event):void {
                try {
                    message.text = "size (bytes): " + numberFormatter.format(fileRef.size);
                    fileRef.upload(new URLRequest(FILE_UPLOAD_URL));
                } catch (err:Error) {
                    message.text = "ERROR: zero-byte file";
                }
            }

            private function fileRef_progress(evt:ProgressEvent):void {
                progressBar.visible = true;
            }

            private function fileRef_complete(evt:Event):void {
                message.text += " (complete)";
                progressBar.visible = false;
            }
        ]]>
    </mx:Script>

    <mx:NumberFormatter id="numberFormatter" />

    <mx:Button label="Upload file"
            click="browseAndUpload();" />
    <mx:Label id="message" />
    <mx:ProgressBar id="progressBar"
            indeterminate="true"
            visible="false" />

</mx:Application>

View source

You’ll notice the previous example doesn’t have a SWF or file upload URL. That would be because I don’t want all of you uploading files to my server. :)

In the previous example, I wrapped the call to fileRef.size in a try..catch block. In ActionScript 3.0, Flash Player throws an error if you attempt to get the size of a zero-byte file.


68 Responses to “Uploading files in Flex using the FileReference class”


  1. 1 Adam Sep 22nd, 2007 at 12:02 am

    Hi, looks like a good example but I am confused about one thing
    in particular. What serverside script are you using to upload the file?
    I noticed this URL “http://www.YOUR-WEBSITE-HERE.com/fileref/uploader.cfm”;
    which I’m guessing is the file to handle the upload? Can you clarify whether
    a serverside script e.g PHP is needed and if so, would you mind posting
    an example. Much appreciated. Love the site by the way, its very useful.

  2. 2 Steve Sep 22nd, 2007 at 2:13 am
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;
    using System.Text;
    
    namespace UploadTest
    {
        ///
        /// Summary description for WebForm1.
        ///
        public class WebForm1 : System.Web.UI.Page
        {
            private void Page_Load(object sender, System.EventArgs e)
            {
                string sResult = "OK";
                if(Request.Files.Count > 0)
                {
                    HttpPostedFile httpPostedFile = Request.Files[0];
                    try
                    {
                        string sFilePath = Server.MapPath(httpPostedFile.FileName);
                        httpPostedFile.SaveAs(sFilePath);
                    }
                    catch(Exception ex)
                    {
                        sResult = ex.Message;
                    }
                }
                else
                    sResult = "No file was uploaded.";
    
                Response.ContentType = "text/xml";
                Response.ContentEncoding = Encoding.UTF8;
    
                Response.Write("<testupload><result>" sResult "</result></testupload>");
            }
    
            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                //
                // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                //
                InitializeComponent();
                base.OnInit(e);
            }
    
            ///
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            ///
            private void InitializeComponent()
            {
                this.Load  = new System.EventHandler(this.Page_Load);
            }
            #endregion
        }
    }
    
  3. 3 Steve Sep 22nd, 2007 at 2:18 am

    Woops - sorry I posted before the message was completed.
    The previous code is for .NET

    The line

    Response.Write("" sResult "");
    

    should read

    Response.Write("<testupload><result>" sResult "</result></testupload>");
    

    [Edit: Peter: Thanks Steve! I edited your comment above.]

  4. 4 peterd Sep 22nd, 2007 at 7:54 am

    Adam,

    Yes, you will need a server-side script that will accept a file and write it to the hard drive (or whatever you want to do with the file). Here’s my test script that I wrote in ColdFusion:

    <cfsilent><cfsetting enablecfoutputonly="true" />
    <cfset req = getHTTPRequestData( )>
    
    <cffile action="UPLOAD" filefield="Filedata" destination="#ExpandPath('.')#" nameconflict="MAKEUNIQUE">
    <cfsavecontent variable="info">
    <html>
    <head></head>
    <body>
    <cfdump label="CFFILE" var="#cffile#">
    <cfdump label="getHTTPRequestData()" var="#req#">
    <cfif IsDefined("FORM")>
        <cfdump label="FORM" var="#FORM#">
    </cfif>
    <cfif IsDefined("URL")>
        <cfdump label="URL" var="#URL#">
    </cfif>
    </body>
    </html>
    </cfsavecontent>
    
    <cffile action="WRITE" file="#ExpandPath('./')##cffile.serverFileName#.dump.html" output="#info#" addnewline="Yes">
    </cfsilent><cfsetting enablecfoutputonly="false" />
    <cfcontent reset="true" />
    <cfoutput>fileName=#CFFILE.serverFile#&fileSize=#CFFILE.fileSize#</cfoutput>
    

    It’s probably quite overkill as it has a bit of debug code in there (it uploads the file and dumps all the file properties to an HTML file so I can see what’s happening).

    If you are using ColdFusion, I believe you can just use the following one line which uploads a file with the header name “Filedata”, and saves it to the same directory as the ColdFusion template:

    <cffile action="upload" filefield="Filedata" destination="#ExpandPath('./')#" nameconflict="OVERWRITE" />
    

    Although the code is really simple and elegant, note that you’d always want to be careful when accepting file uploads. You would want to try and verify that users aren’t uploading executable server-side scripts which they could then call on the server via HTTP. For example, a user could try and upload a PHP script which tries to delete files or databases from your website.

    I’m not a PHP programmer, so I’ll have to leave that for another commenter (or I’m sure there are several solutions on the web if you Google for it). In fact, the Flash documentation does have some sample PHP upload script posted here: “Working with file upload and download“.

    I also found the following article on the Adobe ColdFusion Developer Center, “Multiple file upload with Flex and ColdFusion“.

    Happy Flexing!

    Peter

  5. 5 peterd Sep 22nd, 2007 at 7:56 am

    Setve,

    Thanks for the .NET solution! That’s outstanding!

    Anybody have a snippet for PHP?

    Peter

  6. 6 Saeed Ashour Sep 22nd, 2007 at 8:14 am

    Hi ….

    will be great if anyone post php code for uploading !

  7. 7 peterd Sep 22nd, 2007 at 10:54 am

    Saeed Ashour,

    You can try the PHP code in the Adobe documentation at: http://livedocs.adobe.com/flash/9.0/main/00000320.html

    You may need to tweak the code a bit, as it looks like the code limits the size of upload that will be accepted (max file upload size appears to be 200KB) and it is also checking the file’s type and only allowing certain file types (such as JPEG, GIF and PNG).

    In fact, here’s the code description from the documentation:

    The following code demonstrates file uploads using PHP, and it includes data validation. The script limits the number of uploaded files in the upload directory to 10, ensures that the file is less than 200 KB, and permits only JPEG, GIF, or PNG files to be uploaded and saved to the file system.

    You can also check out this entry in the Adobe Flex Cookbook, “Uploading files from Flex using PHP“.

    Hope that helps,
    Peter

  8. 8 Adam Sep 22nd, 2007 at 4:29 pm

    Saeed Ashour
    said: “great if anyone post php code for uploading !”

    Me three! I have been googling for ages looking for a Flex multi-upload
    example using PHP but most seem to be using ColdFusion which I know
    nothing about unfortunatly, kind of a big ask but would someone mind sending
    me an example? My email is - dyso_au (AT) hotmail.com
    or a link would do :)

  9. 9 Adam Sep 22nd, 2007 at 8:21 pm

    Anyone with a Flex muti-upload example using PHP?
    My email is - dyso_au (at) hotmail.com or a link will do :)

  10. 10 Jimmy Sep 24th, 2007 at 1:12 am

    Adam,
    You can try this link for a multi file upload using php
    http://weblog.cahlan.com/2006/12/flex-upload-component.html

    Cheers!

  11. 11 Mark Sep 25th, 2007 at 8:48 pm

    Hi. This example is great. One question though. Your server generates a response giving the status of the upload from it’s point of view. How is this response accessed from Flex?

    Thanks
    Mark

  12. 12 Mark Sep 25th, 2007 at 10:15 pm

    I have been trawling for a while looking for how you get the server’s response back. So far the best I have seen is setting an HTTPStatus event handler, like this:

    fileRef.addEventListener(HTTPStatusEvent.HTTP_STATUS, onHTTPStatus);
    

    The handler looks like this:

    private function onHTTPStatus (event : HTTPStatusEvent) : void
    {
        Alert.show ("Error:"   event.status);
    }
    

    If the server returns a HTTP status other that 200, this handler is called. In my PHP server, I do something like this:

    if ($fileexists)
      header("HTTP/1.0 501 file exists");
    else if ($couldnotsave)
      header("HTTP/1.0 502 could not save");
    else
      header("HTTP/1.0 200 all ok");
    

    In actionscript, event.status will only get the status number. i.e. it will get “501″ and not “501 file exists”.

    Note that after the HTTPStatus event, a IOErrorEvent is also issued.

    Mark

  13. 13 Mark Sep 25th, 2007 at 10:44 pm

    I’m back! The way to get the response is easy (but not documented in the Flex doc from what I can see):

    fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onUploadCompleteData);
    
    private function onUploadCompleteData (event : DataEvent) : void
    {
        Alert.show (event.data);
    }
    

    Data contains whatever was issued, so in my PHP:
    echo “hello”;

    puts “hello” in event.data.

    Hope this saves someone some time.

    Mark

  14. 14 peterd Sep 25th, 2007 at 11:11 pm

    Mark,

    Good work, you beat me to a response! Correct, the way to grab the server response is by listening for the uploadCompleteData event like you said. It should be documented in the Flex 2.0.1 language reference documentation (click here).

    I’ll undoubtedly cover this in an upcoming example as this is relatively new to Flash Player (added in Flash Player 9.0.28.0, I believe).

    Peter

  15. 15 Mellisa Oct 2nd, 2007 at 8:04 pm

    Hi there, I’ve been looking for a working example for server side written in JSP for upload and download file. Will appreciate anyone who can give me the code.

  16. 16 Anthony Oct 15th, 2007 at 12:33 pm

    For those of you who want to use Steve’s ASP.NET fileupload in VS 2003 modify these minor errors:

    1. Change this:

    Response.Write(”" sResult “”);

    to this:

    Response.Write(”" sResult “”);

    2. Change this:

    this.Load = new System.EventHandler(this.Page_Load);

    to this:

    this.Load = new System.EventHandler(this.Page_Load);

    For some reason I couldn’t get this to work in VS 2005. Great job Steve for the .net code.

  17. 17 Anthony Oct 15th, 2007 at 12:37 pm

    Peter, are ” ” (plus signs) disabled?

  18. 18 peterd Oct 15th, 2007 at 1:36 pm

    Anthony,

    Ha, seemingly. Posting comments have always been kind of buggy in this template (its very AJAX heavy).

    Try escaping the + signs with a backslash.
    Similarly, excape > signs with &gt; and < with &lt;

    Sigh,

    Peter

    (blah, i see hwo hard it is to post the “+” signs. try wrapping everything in a <pre /> tag and cross your fingers.)

  19. 19 jered jeruel Oct 30th, 2007 at 3:18 am

    any example of for file upload using JSP and then will display also hash code in Flex??? Thanks.

  20. 20 vonnhugo Dec 11th, 2007 at 9:38 am

    for jsp:

    items = upload.parseRequest(request);
    int counter = 0;

    for(FileItem item : items) {
    try {
    File uploadedFile = new File(uploadDir File.separator item.getName());
    item.write(uploadedFile);

    out.println(”" uploadedFile.getAbsolutePath() “”);
    }
    catch(IOException ioe) {
    System.out.println(”Problem copying temp file. ” ioe);
    }

    try {
    MessageDigest md = MessageDigest.getInstance(”MD5″);
    byte[] message = item.getString().getBytes();
    md.update(message);
    byte[] messageDigest = md.digest();

    StringBuffer sb = new StringBuffer();
    for(int i=0; i” sb.toString() “”);
    }
    catch(Exception e) {
    System.out.println(”Unknown hash algorithm ” e);
    }

    counter ;
    }

    %>

    ——————–

    this works with Apache Tomcat 5.5

    an example here: http://www.webtitude.com/uploadToolTest2/Uploader.html

    don’t bother about uploading so much. the script there deletes the file from server after hash code is displayed.

    - vonnhugo (a.k.a. kris) with rey’s help for the JSP :)

  21. 21 vonnhugo Dec 11th, 2007 at 9:46 am

    yikes… i forgot that codes will not show well here. but the idea is there. email me (vonnhugo[at]hotmail.com) if you need these craps. :D

    Update: Here’s the code:

    <%@page import="java.io.IOException"%>
    <%@page import="java.io.File"%>
    <%@page import="java.io.InputStream"%>
    <%@page import="java.io.FileInputStream"%>
    <%@page import="java.security.MessageDigest"%>
    <%@page import="org.apache.commons.fileupload.FileItem"%>
    <%@page import="java.util.List"%>
    <%@page import="org.apache.commons.fileupload.servlet.ServletFileUpload"%>
    <%@page import="org.apache.commons.fileupload.disk.DiskFileItemFactory"%>
    <%@page import="org.apache.commons.fileupload.FileUpload"%>
    
    <?xml version="1.0"?>
    <myUpload>
    
    <% 
    
    String uploadDir = pageContext.getServletContext().getRealPath("uploads");
    
    File dir = new File(uploadDir);
    if(!dir.exists()) {
        dir.mkdir();
    }
    
    DiskFileItemFactory factory = new DiskFileItemFactory();
    ServletFileUpload upload = new ServletFileUpload(factory);
    
    @SuppressWarnings("unchecked")
    List<FileItem> items = upload.parseRequest(request);
    int counter = 0;
    
    for(FileItem item : items) {
    
        File uploadedFile = new File(uploadDir + File.separator + item.getName());
    
        try {
            item.write(uploadedFile);
    
            out.println("<file"+ counter +">"+ uploadedFile.getAbsolutePath() +"</file"+ counter +">");
        }
        catch(IOException ioe) {
            System.out.println("Problem copying temp file. " + ioe);
        }
    
        InputStream is = null;
    
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
    
            //byte[] message = item.getString().getBytes();
            //md.update(message);
    
            byte[] buffer = new byte[1024];
            is = new FileInputStream(uploadedFile);
            int read = 0;
    
            while( (read = is.read(buffer)) > 0) {
                md.update(buffer, 0, read);
            }    
    
            byte[] messageDigest = md.digest();
    
            StringBuffer sb = new StringBuffer();
            for(int i=0; i<messageDigest.length; i++) {
                sb.append(Integer.toHexString( (int)(messageDigest[i] & 0xff)  ));
            }
    
            out.println("<md5hash"+ counter +">"+  sb.toString() +"</md5hash"+ counter +">");
        }
        catch(Exception e) {
            System.out.println("Unknown hash algorithm " + e);
        }
        finally {
            if(is != null) {
                is.close();
            }
        }
    
        counter++;
    }
    
    %>
    
    </myUpload>
    
  22. 22 Rockman Jan 3rd, 2008 at 8:02 am

    Anyone have problems using multiple uploads with a Windows box? I have a great upload that works great on any mac computer but IO_ERROR on any windows box…

    BTW, I am using the Adobe example scripts and trapping for IO_Error, i think it resutls in #2038..

    any insight would be great , thanks

  23. 23 pankaj Jan 6th, 2008 at 11:01 pm

    i think it’s a problem of rights to file or directory from/to where we want to Download/Upload

  24. 24 Abhishek Jan 18th, 2008 at 1:25 am

    could u tell me how to upload files on server from flex to Ruby on Rails ?

  25. 25 Mukesh Sahu Feb 7th, 2008 at 10:34 am

    Hello abhishek
    even i am looking for the same thing.
    i am using RoR as back-end in my flex project.
    Please anyone guide me regarding ruby code for uploading the files.
    thanks in advance.

  26. 26 Paul Mar 1st, 2008 at 1:17 pm

    What happens if you want to upload (import might be a better term) a file into a client side component such as an RichTextEditor box? The user would then be able to edit the file, and either save it or send it to the server.

    Anyone know how to do this preferably without a server roundtrip.

  27. 27 asha Mar 6th, 2008 at 11:22 pm

    hi! i just want to know how to upload a file on server using flex2.
    please send reply to this mail as soon as poosible….

  28. 28 peterd Mar 6th, 2008 at 11:49 pm

    asha,

    Check out the FileReference class (http://livedocs.adobe.com/flex/201/langref/flash/net/FileReference.html), or more specifically, the FileReference class’s upload() method.

    Peter

  29. 29 Muzzammil Apr 2nd, 2008 at 12:28 am

    i am using backend as java,can anyone post the server side code for image uploading in java which uses this code in the client side

  30. 30 rconceiver Apr 10th, 2008 at 2:04 am

    is there any way to get the absolutepath in flex?

  31. 31 peterd Apr 10th, 2008 at 8:20 am

    rconceiver,

    No.

    Peter

  32. 32 epox Apr 24th, 2008 at 10:28 pm

    Hello! i’m trying to upload files to .net with c#, but i’m a newbie with .net, in what kind of file do i put that snippet from steve???, and how do i call it??? thanks!

  33. 33 Alain May 7th, 2008 at 6:22 pm

    Hello,
    I don’t think Paul’s question was answered and my questions goes in a similar direction.
    Is there a way to get the image data from the FileReference object? Or is there another objet that would allow me to?

    The reason is, I would like to covert the image data to a bitearray and send it with other information to AMFPHP as a remote Object.

    I’ve been looking around for an example or tutorial that would come close to this but I can’t find one that actually show how to get the user to load (import) the image in my flex app. from a filebrowser like component.

    Any help would be greatly appreciated.
    Thanks
    -Alain

  34. 34 peterd May 7th, 2008 at 6:37 pm

    Paul,

    I don’t think this is possible without a server round-trip. You’d have to get the user to select a file on their computer, upload that file to a webserver using ColdFusion, PHP, ASP, Java, etc, then download the file and display it in the RichTextEditor control. Then, to save the file locally you would probably would need to send the contents of the RichTextEditor to a server and call FileReference again to save the file. The Flash Player does not allow direct file access from an online Flex application to the user’s hard drive for editing and saving files directly. If you were building a desktop application, you could do this in AIR though.

    Alain,

    Similarly, you’d have to use the FileReference object to have the user select a file from their operating system. Next, you would need to upload the file to a server to save the file and then redownload the image and get the image data that way (for the same reasons as above, Flash Player doesn’t allow for immediate data access without sending the data to the server).

    You may want to ask the same question on a high traffic list like FlexCoders and see if anybody else has any clever solutions or workarounds.

    Peter

  35. 35 Alain May 7th, 2008 at 6:47 pm

    Thank you for the quick response Peter. I will try your suggestion about the FlexCoders list.
    You have a great site by the way. Keep up the good work!

    -Alain

  36. 36 io error 2038 on Tomcat 5.5 on Linux May 19th, 2008 at 5:02 am

    Can any one help me out with file uploading. I have written a MXML to upload the file using file reference object. This calls the JSP to upload the file. This seems to work on windows for tomcat 5.5

    If i do the same thing on linux I am getting io error 2038. Dont seem to understand the reason for it cause the windows and linux tomcat configuration is the same.

    Please advise !!!!

  37. 37 peterd May 19th, 2008 at 12:59 pm

    io error 2038 on Tomcat 5.5 on Linux,

    Can you file a bug at https://bugs.adobe.com/flashplayer/ and include a simple test case.

    Peter

  38. 38 Fernando Escobar May 28th, 2008 at 9:18 am

    Hey guys. I’m trying to upload files using JSP as a server-side upload handler, and I really appreciate the contribution on how to do it with JSP.
    But I’m having a problem, every time I try to upload something the browser keeps telling me about the error#2038 I/O error, and I’ve tried with Explorer and FIrefox and still nothing.
    I’ve read a lot about why this could be happening and it seems that the server I’m running this (which is Tomcat) has a mod_security enabled option. So please I’m begging for help, I don’t know what to do. Is there a way to disable mod_security in Tomcat? Or is it something else the problem with the error code #2038?
    Thanks in advance for any replies.

  39. 39 iCao Jun 6th, 2008 at 4:19 am

    The FileReferene.upload doesn’t work !!! It work only if you use IE on windows, in any other Case nothing append (no error )

    https://bugs.adobe.com/jira/browse/FP-78

  40. 40 Is their a fix? Jun 26th, 2008 at 4:02 am

    Hi all,

    I have a problem uploading files from Mac OSX using a similar method.

    All is fine on Windows on any browser.
    All is fine on OSX as long as my files that I want to upload don’t have spaces in the name.

    Does anyone know how to get round this problem?

    Or do I have to check the filename the user wants to upload and if it has spaces in tell them to rename the files because Adobe can’t get their act together!

    Also are any other characters illegal in the filename only on OSX but I hear the same problems on linux also.

  41. 41 Nitish Dhar Jul 5th, 2008 at 4:53 am

    Actually i have designed a flex page . Now i want to have a browse button on the page which takes the path of an image to be uploaded from my local disk and when i click upload it displays it on the same flex page(may be in a text area) . Plz help??

  42. 42 G.vinay kumar Jul 9th, 2008 at 2:11 am

    In the above example if i have a SWF or file upload URL and that to i want to upload files in my server only
    will u plzzz reply with that code
    waiting for u r reply

    thanks and regrads
    G.vinay kumar
    Ghoom solutions
    Hyderabad

  43. 43 David Patrick Jul 9th, 2008 at 5:01 pm

    Thank you

  44. 44 Sam Jul 10th, 2008 at 12:51 am

    Hi. What would i have to do if i wanted to upload it to a directory in my local drive.
    What would i put in place of
    private const FILE_UPLOAD_URL:String = “http://www.YOUR-WEBSITE-HERE.com/fileref/uploader.cfm”;

  45. 45 Sam Jul 10th, 2008 at 6:39 pm

    And one more thing. Where does it get stored. What exactly is stored in the .cfm file.

  46. 46 Sam Jul 10th, 2008 at 6:56 pm

    i uploaded it to a remote server here is the link
    http://free.calypsohosting.com/sam2214/testUpload.html

  47. 47 Sam Jul 10th, 2008 at 6:57 pm

    When it displays completed. Where is it stored?

  48. 48 peterd Jul 10th, 2008 at 11:29 pm

    Sam,

    I believe you can only upload files to a web server, not your local drive (unless of course your local computer had a web server installed and running).

    You can see the contents of the .CFM file in a previous comment; http://blog.flexexamples.com/2007/09/21/uploading-files-in-flex-using-the-filereference-class/#comment-2777

    And when it displays “completed”, the file would be stored wherever you specified in the <CFFILE /> tag.

    Peter

  49. 49 Dan Jul 11th, 2008 at 1:12 pm

    Peter this was a great article.

    I was wondering how to go about taking this a step further and writing to a XML file after each upload.

    Just basic information like name, extension, type etc. I know how to access all that, but what I’ve written for the actual writing of the XML file part seems to slip up. I know how to read from an XML file into flex, but writing out to one is giving me the issue. Any ideas/help?

    Thanks

  50. 50 Dan Jul 18th, 2008 at 12:31 pm

    Decided to go with server side XML file writing. ;) Works like a charm

  51. 51 Sam Jul 20th, 2008 at 8:27 pm

    Hi, i’ve got another problem. I need to create a real-time graph application, does anyone have an example? The graph should increase on the x axis each tick. Anyone has any idea?

  52. 52 Kate B. Aug 11th, 2008 at 6:43 am

    Hello everybody!

    I’v learn about Flex and server-side techologies less then month ago. I’ll be very glad, if somebody, step by step, describes me how can I force my Flex application to upload generated-in-time file to TomCat server using some Java technologies…

    Thank you!=)

  53. 53 Mai Ta Aug 19th, 2008 at 9:10 pm

    Hi all!
    I have a problem with Upload file with FileReference.
    I want to get path of file which i browse from client.
    But i can’t get it!
    Everyone can help me in this case, please!
    Thanks for reading my problem.

  54. 54 peterd Aug 19th, 2008 at 9:14 pm

    Mai Ta,

    I don’t believe that Flash Player returns that information (possibly for security reasons).
    You could try searching for a bug/enhancement in the public Flash Player bug base at http://bugs.adobe.com/flashplayer/. Feel free to file a bug/enhancement if one doesn’t already exist. If you post the bug number here a few of us can vote and/or subscribe.

    Thanks,
    Peter

  55. 55 Mai Ta Aug 19th, 2008 at 9:36 pm

    Hi Peterd!
    Thanks for your reply!
    So do you have any resolve for my problem?
    I really need to get this path file for my project.
    I don’t see any examples for this problem.
    Sorry because of my problem!
    Thanks,
    Mai

  56. 56 peterd Aug 19th, 2008 at 9:42 pm

    Mai Ta,

    I am not aware of any solutions or workarounds for this problem.
    You could try asking on FlexCoders or some other list with lots of traffic and see if anybody has any ideas, but as far as I know, it is not possible to get the full path of a file when doing a file upload with the FileReference class and Flash Player.

    Sorry,
    Peter

  57. 57 Mai Ta Aug 20th, 2008 at 1:57 am

    Hi Peterd!
    Thanks for your help very much!
    Maybe i will change the way to upload file in Flex or only get file name in my project.
    Thank you so much!
    Nice day to u!
    Thanks,
    Mai

  58. 58 euni Aug 28th, 2008 at 12:37 am

    hi! petered!!

    I can’t get xml string encoded by euc-kr when UPLOAD_COMPLETE_DATA event is occured.
    I checked correct xml string on html, tomcat logs.
    But only in Flex, xml string was bloken.

    Plz help me ~~~ lol.

    ps. There is no problem with HTTPService request/response.

    public function fileRequest(url:String):void
    {
    var urlRequest:URLRequest = new URLRequest(url);
    urlRequest.method = "POST";
    file.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, fileResultHandler);
    file.upload(urlRequest,"FileData",false);
    }

    --------------------------------------------------------
    HTML, Tomcat Log
    --------------------------------------------------------

    테스트1

    01000000001

    abc1

    --------------------------------------------------------
    FLEX
    --------------------------------------------------------

    Å׽ºƮ1

    01000000001

    abc1

  59. 59 peterd Aug 28th, 2008 at 1:53 am

    euni,

    Sorry, I don’t know why that would happen with euc-kr. Can you file a bug at http://bugs.adobe.com/flashplayer/ and attach any source code or files you think are relevant and somebody on the Player team may be able to have a look.

    Peter

  60. 60 Gino Sep 19th, 2008 at 12:51 am

    Hi

    I’ve been trying to make this work using java spring as backend. But I can’t make it work. Spring has an implementation for file upload and Im using that as my backend.

    Anyone out there got any idea how to do this?

    Thanks :D

  61. 61 Boris Oct 8th, 2008 at 6:56 am

    Hi Peter, how can i prevent the SecurityError: Error #2148: when i’m uploading files from my local desktop to an outside-the-sandbox-server. I tried a lot of hacks (crossdomain.xml, Security.allowDomain, eg) but this error, everytime appears. But the funny thing is, that the upload is complete, but i didn’t get any data from the server, that gives succes. Locally with localhost everything works finest.

  62. 62 Boris Oct 8th, 2008 at 8:04 am

    Sorry Peter, just ignore my last comment - it was not the fault of the filereference, but i did something wrong with the data that was sent from the server

  63. 63 Gilbert Oct 8th, 2008 at 3:05 pm

    I am working on an AIR app. that records videos, using RED5. Once the user is happy with a video the app uploads the flv to a Windows server.

    It works fine for short videos (small files), but when the file size is larger (I don’t know the threshold) it does not work anymore.

    Do you know how to allow the app. or the asp.net script to work with large files?

    Thanks.

  64. 64 Ronny Oct 22nd, 2008 at 4:08 am

    I try to to upload a image to a server, but often the images are huge and I need to resize them before I upload them. Is there a way for flex to do this on the client side so I don’t have to uploade 20mb and then resize it.

    Help or an example is preciated.
    Regards
    Ronny

  65. 65 peterd Oct 22nd, 2008 at 7:21 am

    Ronny,

    I’ve never tried resizing images/BitmapData before uploading it to a server-side script.
    You may want to try asking on the FlexCoders mailing list and see if anybody there has any suggestions.

    Sorry,
    Peter

  66. 66 jimmi Oct 28th, 2008 at 11:03 pm

    greets,
    nice blog ;)
    I have a question about that fu… ahm nice ;) file upload feature after messing around with it a few ours long. So, here my prob: I’m using the aspx and I’ll say it’s working. I set all the events I need but in that special case the httpStatusEvent says nothing, only the openEvent stucks on [Event type=”open” bubbles=false cancelable=false eventPhase=2] progress bar says it’s ready but there is no file in the directory (and yeah I set allready all the rights to that spec. dir.)
    Somebody an idea?

    thanks a lot.

    jimmi

  67. 67 Paul Dec 2nd, 2008 at 2:49 pm

    I’m trying to upload files and it works great in Windows, but on OS X it doesn’t ever hit my URLRequest page. Is there any insight on what is different between the two, or something I need to do in for OS X?

  68. 68 deenalex Dec 3rd, 2008 at 12:00 am

    Hi Everyone,

    Can any one help me to convert any type of Video files into .flv format (i.e) flash video format.

    I mean, if we browse and select any type of video, it (Flex Program) should convert it to .flv format.

    Thanks in Advance……

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".




September 2007
M T W T F S S
« Aug   Oct »
 12
3456789
10111213141516
17181920212223
24252627282930

Badge Farm

  • Firefox 2
  • Powered by Redoable 1.2
  • Feeds burnt by Feedburner
  • Feed