Chaitanya Gudala
Chaitanya Gudala

Reputation: 305

How to send binary content to a servlet in Action Script

I have an action script function in a file which sends a pdf file as binary content to a servlet as shown below.

private function savePDF(pdfBinary:ByteArray, urlString:String):void{

            try{
                Alert.show("in savePDF urlString" +urlString);
                //result comes back as binary, create a new URL request and pass it back to the server
                var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");

                var sendRequest:URLRequest = new URLRequest(urlString);
                sendRequest.requestHeaders.push(header);
                sendRequest.method = URLRequestMethod.POST;
                sendRequest.data = pdfBinary;

                Alert.show("in savePDF calling sendToURL"); 

                sendToURL(sendRequest);
            }catch(error:*){
                Alert.show("in savePDF err" +error);    
                trace(error);
                }
            } 

This code works fine in flashplayers versions like 10,11,13

But fails in flashplayers of higher versions like 14.0.0.126 or above.

I get the following error

SecurityError: Error #3769: Security sandbox violation: Only simple headers can be used with navigateToUrl() or sendToUrl().

Any suggestions on how to resolve this ?

Upvotes: 0

Views: 177

Answers (1)

CyanAngel
CyanAngel

Reputation: 1238

You could try using a URLLoader instead of sendToURL()

Alert.show("in savePDF urlString" +urlString);
var header:URLRequestHeader = new URLRequestHeader("Content-type", "application/octet-stream");

var sendRequest:URLRequest = new URLRequest(urlString);
sendRequest.requestHeaders.push(header);
sendRequest.method = URLRequestMethod.POST;
sendRequest.data = pdfBinary;

Alert.show("in savePDF calling URLLoader"); 

var loader:URLLoader = new URLLoader();
loader.load(sendRequest);

Upvotes: 2

Related Questions