Go Back   CodingForums.com > :: Client side development > Flash & ActionScript > Adobe Flex

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-15-2011, 02:44 PM   PM User | #1
Stooshie
Regular Coder

 
Stooshie's Avatar
 
Join Date: Mar 2008
Location: Dundee, Scotland
Posts: 376
Thanks: 9
Thanked 39 Times in 39 Posts
Stooshie is on a distinguished road
Question Converting ByteArray to ArrayCollection

I am uploading a file to a web service. I have created a FileReference and called FileReference.browse(). Once that is loaded, I call FileReference.load() which loads the image into memory into FileReference.data as a ByteArray().

The web service I am using requires the data for the file to be passed as an ArrayCollection().

I have tried casting it as a ByteArray and converts it to null.

Any ideas how I can convert a ByteArray into an ArrayCollection?
__________________
Regards, Stooshie
O
Stooshie is offline   Reply With Quote
Old 02-16-2011, 10:34 AM   PM User | #2
Stooshie
Regular Coder

 
Stooshie's Avatar
 
Join Date: Mar 2008
Location: Dundee, Scotland
Posts: 376
Thanks: 9
Thanked 39 Times in 39 Posts
Stooshie is on a distinguished road
Smile Solution, of sorts!

I managed to fix this by changing the web service to accept base64Binary. If anyone is interested, here is the php to do this, using the nusoap PEAR extension.

Register the service
PHP Code:
    $server->register("UploadFile",
        array(
            
"bytes" => "xsd:base64Binary"
            
"cp_id" => "xsd:string""filename" => "xsd:string"
        
),
        array(
"return" => "xsd:boolean"),
        
$ns,
        
"$ns#UploadFile",
        
"rpc",
        
"encoded",
        
"Upload a File"
    
); 
Implement the service
PHP Code:
    function UploadFile($bytes$folder_path$filename)
    {
        global 
$path_to_html;
        
$file_path $path_to_html.$folder_path."/".$filename;
        
$fp fopen($file_path"w");
        if( 
is_array($bytes) )
        {
            foreach(
$bytes as $k => $v)
            {
                
fwrite($fp$v);
            }
        }
        else
        {
            
fwrite($fp$bytes);
        }
        
fclose($fp);
        return 
true;
    } 
I have posted this code in case it helps someone else although I am still not sure how to convert a ByteArray to an ArrayCollection in Flex.
__________________
Regards, Stooshie
O
Stooshie is offline   Reply With Quote
Reply

Bookmarks

Tags
arraycollection, bytearray, convert

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:13 AM.


Advertisement
Log in to turn off these ads.