I am using this adobe example under “reading and writing objects” to try and convert an XML file to a byteArray and save the file somewhere. I use this to upload the file to s3. When i download the XML file with s3 i get 4 random characters in front of the XML file. Looking into the issue [example of what i think is happening], it seems that the extra characters are being created with the encoding scheme. However, adobes example uses writeObject to convert an XML to a byteArray, so I don’t see how i am using the incorrect encoding scheme.
my code is fairly simple.
creating the byteArray:
var _bookXml:XML = _book.serialize(); //converts book to XML
var photobookXmlName:String = photobookToken + "_layout.xml";
_s3uploader.uploadObjectToS3(_bookXml, photobookXmlName); //uploads XML
and the uploadObjectToS3 code:
public function uploadObjectToS3(file:Object, objectName:String):void{
var data:ByteArray = new ByteArray;
data.writeObject(file);
data.position = 0;
//code to do s3 upload
}
heres a before/after example XML file i used as a test case:
before:
<xml>
<test>data</test>
</xml>
after:
��5<xml>
<test>data</test>
</xml>
any idea how to fix this issue so I dont get random characters? I’ve tried a few things but they didn’t work.
thanks
edit: before anyone suggests, i already trtied changing the uploadObjectToS3 input form an object to a ByteArray. It didnt change anything.
You are using
data.writeObject(file);. Those are not random characters, those are serialization markers.You aren’t sending an xml document to S3, you are sending a serialized Actionscript
XMLobject (in AMF3 format)._bookXml.toXMLString()will give you the xml document as a string. then you should be able to useByteArray.writeMultiByte()to get what you want. Check out the following example:The output is:
The difference is the first is a serialized object (that you could use
.readObject()to deserialize the object out of the byte array back into aXMLobject in flash). The latter is simply the raw bytes of the string (in utf-8).In your case, I would suggest something like this: