Using rubyamf to write a bytearray to file sent from flex

April 24th, 2009

RubyAMF converts a bytearray from AMF to an array of fixnums. Those fixnums represent characters which represent the bytes.

This is how to write the data to file:

1
2
3
4
5
byteArray = rubyamf_params[2]; #assuming a ByteArray was passed as arg 2
fout = File.open( path, 'wb' );
data = byteArray.pack('c'*byteArray.length);
fout.puts(data);
fout.close

Took me a while to figure this out and I didn’t see any instruction elsewhere on the web. I’m currently using this to save images to disk from flex.

3 Responses to “Using rubyamf to write a bytearray to file sent from flex”

  1. DarrinW Said:

    Thanks Aaron,

    That’s exactly what I’ve been looking for.

  2. Marty Said:

    Hey Aaron,

    Thanks, this is half the problem. I still can’t seem to get the fetching side to work either (i.e. reading a byte array from ruby->flex). Do you have a silver bullet for that?

    Thanks,

    Marty

  3. Aaron Spjut Said:

    Marty:
    I haven’t actually tried sending back a byte array. I’m sending image data as a byte array to the server then saving the images to disk on the server. The client can then load the images with a url.

Leave a Reply