How to send binary data from AS3 through Java to a filesystem?

后端 未结 2 403
余生分开走
余生分开走 2021-01-24 11:33

I\'ve got XML data in AS3 that needs to be compressed, validated on my Java Google App Engine servlet then saved to a file in Google Cloud Storage. Later that file will be opene

2条回答
  •  Happy的楠姐
    2021-01-24 12:38

    I would base64 encode before you POST if from the client, store it that way in a TextProerty, then base64 decode / decompress when received back at the client. If you want to store it as binary on GAE, then base64 decode it into a Blob. Here are some code snippets I pieced together using your code, and something similar I do using HttpService -- apologies in advance for not extensively proofing it. HTH.

    private var _serviceHttp:HTTPService = new HTTPService;
    
    private function postBytes():void {
        var xml:XML = value;
        var bytes:ByteArray = new ByteArray();
        bytes.writeObject(xml);
        bytes.position = 0;
        bytes.compress();
        var enc:Base64Encoder = new Base64Encoder();
        enc.encodeBytes(bytes, 0, bytes.length);
        var myObj:Object = new Object();
        myObj["bytes"] = enc.toString();
        // myObj["other_variables"] = your_other_varaibles;
        _serviceHttp.method = "POST";
        _serviceHttp.resultFormat = "flashvars";
        _serviceHttp.url = your_url_here;
        _serviceHttp.addEventListener(ResultEvent.RESULT, urlHandler);
        _serviceHttp.addEventListener(FaultEvent.FAULT, urlErrorHandler);
        _serviceHttp.send(myObj);
    }
    

提交回复
热议问题