0

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 ?

Chaitanya Gudala
  • 305
  • 1
  • 3
  • 22
  • This is a known issue caused by a security update in a recent version of Flash Player; see https://forums.adobe.com/thread/1521470 and https://bugbase.adobe.com/index.cfm?event=bug&id=3759971. @CyanAngel's answer will let you send your request without being blocked by this security check. – Brian Nov 10 '14 at 20:58
  • Is there any issue with "passing data to swf file using FlashVars variable" in recent version of Flash Player ? I get all the variables as null – Chaitanya Gudala Nov 11 '14 at 05:57
  • Not that I know of. However, it can be tricky to get right if you're not sure how to pass in variables. – Brian Nov 11 '14 at 08:40

1 Answers1

2

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);
CyanAngel
  • 1,240
  • 1
  • 14
  • 28
  • I get the following error if I use URLLoader Error #2044: Unhandled securityError:. text=Error #2048: Security sandbox violation: – Chaitanya Gudala Nov 19 '14 at 14:56
  • 1
    You may need to set up a cross domain policy, see : http://stackoverflow.com/questions/5157089/flex-security-sandbox-violation-error2048 – CyanAngel Nov 19 '14 at 14:58