AS3 ByteArray Uploader

Last post 07-13-2009 5:52 PM by BarryR. 10 replies.
Page 1 of 1 (11 items)
Sort Posts: Previous Next
  • 05-08-2008 3:39 PM

    AS3 ByteArray Uploader

    I'm creating an app that creates large amounts of binary data in memory and then uploads it to nirvanix as a file.
    I thought I would share this utility in case others might need to do the same.

    The link below includes a class to upload a bytearray of any size to nirvanix and works in Flash, Flex, and AIR on or offline.
    It uploads the data in chunks across multiple requests using the  content-range feature.
    It requires that you get the storage node and upload token on your own first, but provides a
    quick wrapper class to hold the host, uploadToken, destFolderPath, and fileName

    Example Usage:

    var data:ByteArray = createYourMassiveByteArray();

    var storageNode:NirvanixStorageNode = new NirvanixStorageNode();
    storageNode.host = "...";
    storageNode.uploadToken = "...";
    storageNode.destFolderPath = "...";
    storageNode.fileName = "...";

    var uploader:NirvanixBinaryUploader = new NirvanixBinaryUploader(storageNode, data);
    uploader.addEventListener(Event.COMPLETE, onComplete);
    uploader.addEventListener(ProgressEvent.PROGRESS, onProgress);
    uploader.upload();

    http://www.digimix.com/nirvanix/NirvanixAS3BinaryUploader.zip 

  • 05-09-2008 8:53 AM In reply to

    • BarryR
    • Top 10 Contributor
    • Joined on 07-20-2007
    • San Diego
    • Posts 824

    Re: AS3 ByteArray Uploader

     Thank you for this great contribution.  If you don't mind, I would like to add this to our files area as a user contribution as well as a link to your site.

    Best Regards,
        Barry R.

    IM Support (Feel free to add me)

    MSN: barryruffner@live.com
    Gmail: barryruffner@gmail.com
  • 01-13-2009 8:19 PM In reply to

    Re: AS3 ByteArray Uploader

    hello  Digidoodi need help.

     Can you send me the C# code to receive the Flex bytearray and save them as a jpg file?? Please

     

    Very thanks

  • 07-12-2009 2:09 AM In reply to

    Re: AS3 ByteArray Uploader

    I believe your awesome pieced uploader has been broken by the latest version of flash:

    http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes_02.html#head34

     

    The pieces that follow the first fail due to the fact that it was not triggered by user interaction.  Can anyone confirm this?

  • 07-12-2009 5:43 PM In reply to

    • BarryR
    • Top 10 Contributor
    • Joined on 07-20-2007
    • San Diego
    • Posts 824

    Re: AS3 ByteArray Uploader

    I think as long as you are able to create the class and upload from a button press it gets past this requirement.  I haven't tested this specifically but that's my understanding.   Are you seeing a specific case fail?

    Regards,
          Barry R.

    IM Support (Feel free to add me)

    MSN: barryruffner@live.com
    Gmail: barryruffner@gmail.com
  • 07-12-2009 8:29 PM In reply to

    Re: AS3 ByteArray Uploader

    Well the problem is with the successive uploads.  The first upload, of course, goes through perfectly fine, as it's triggered from user interaction.

     

    However, when the next piece is prepared for upload (which is triggered from onCurrentRequestComplete), I get the following exception:

    SecurityError: Error #2176: Certain actions, such as those that display a pop-up window, may only be invoked upon user interaction, for example by a mouse click or button press.
     at flash.net::URLStream/load()
     at flash.net::URLLoader/load()
     at Classes.file::UploadPostHelper/nextRequest()
     at Classes.file::UploadPostHelper/onCurrentRequestComplete()
     at flash.events::EventDispatcher/dispatchEventFunction()
     at flash.events::EventDispatcher/dispatchEvent()
     at flash.net::URLLoader/onComplete()

     

  • 07-13-2009 1:29 AM In reply to

    Re: AS3 ByteArray Uploader

    Hmm... may have stumbled on to something...

    http://bentimagemedia.com/?p=34

  • 07-13-2009 4:22 AM In reply to

    Re: AS3 ByteArray Uploader

    According to this page:

    http://bentimagemedia.com/?p=34

    This should work, as the original URLLoader request was done via user interaction (a mouse click), and the onComplete was triggered from an action that stemmed from this mouse click.  For some odd reason, though, that doesn't seem to be the case, and I still get an Error #2176

     

    Any ideas?

  • 07-13-2009 1:53 PM In reply to

    • BarryR
    • Top 10 Contributor
    • Joined on 07-20-2007
    • San Diego
    • Posts 824

    Re: AS3 ByteArray Uploader

    What if you did a loop for every file and submitted them one after another.  Another thought was to have the loop pause until a global variable is set with the onComplete and then submit the next file.   I'm not sure if that is possible but may be something you could try.

    Regards,
           Barry R.

    IM Support (Feel free to add me)

    MSN: barryruffner@live.com
    Gmail: barryruffner@gmail.com
  • 07-13-2009 3:05 PM In reply to

    Re: AS3 ByteArray Uploader

    Well the idea behind the code above is that it submits pieces of a file - I'm not sure the server would know how to correctly process the data if the pieces aren't sent in order.

     

    As for a waiting/pausing loop, that definitely won't be allowed by Flash.  Flash functions have to execute very quickly as they are done on a per-frame basis (which is why there are callbacks for just about everything, including onComplete).  It'd report an exception if you have a wait loop go for more than a couple of seconds.

  • 07-13-2009 5:52 PM In reply to

    • BarryR
    • Top 10 Contributor
    • Joined on 07-20-2007
    • San Diego
    • Posts 824

    Re: AS3 ByteArray Uploader

     I see, I tried to get a flash uploader to do this and was not very successful.  Instead we wrote a Java Upload applet that does the same thing.  I am anticipating a release soon but this means integration with a flash based site could be a bit ugly.   The applet lets you call upload via javascript or via a button interface and also has javascript callbacks.  This obviously needs to be signed and is also designed to run in the background behind JavaScript making it fit for most sites.  It still needs to be tested more throughly before release but perhaps I can arrange a pre-release if there is enough interest.

    The initial place it will be used is on the PHP Web Client that we have running on our test site.

    Regards,
          Barry R.

    IM Support (Feel free to add me)

    MSN: barryruffner@live.com
    Gmail: barryruffner@gmail.com
Page 1 of 1 (11 items)