Latest Google Chrome Browser stops Flash (AS3) sen

2019-08-08 23:48发布

I have the following code in my AS3 Flash code that takes a screenshot within the swf using JPGEncoder and sends it to the url where i write it to a file in PHP.

This code has worked for a long time but since the very latest Google Chrome Update 33.0.1750.146 the function just stops and the page fails to redirect. Nothing gets sent to save.php

I have tested this in Safari, Firefox, IE and lower versions of Chrome up to 33.0.1750.117 and all work perfectly fine.

So surely it's an issue purely with the latest Chrome? Is there anything i can do to solve this?

My code is:

AS3:

function createJPG(m:MovieClip, q:Number, fileName:String) {
    var jpgSource:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight);
    jpgSource.draw(stage);
    var jpgScreenshot: BitmapData = new BitmapData(362, 310);
    jpgScreenshot.copyPixels(jpgSource, new Rectangle(288, 89, 362, 310), new Point(0, 0));
    var jpgEncoder:JPGEncoder = new JPGEncoder(q);
    var jpgStream:ByteArray = jpgEncoder.encode(jpgScreenshot);
    var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
    var jpgURLRequest:URLRequest = new URLRequest ("http://www.url.com/save.php");      
    jpgURLRequest.requestHeaders.push(header);              
    jpgURLRequest.method = URLRequestMethod.POST;               
    jpgURLRequest.data = jpgStream;
    var jpgURLLoader:URLLoader = new URLLoader();   
    navigateToURL(jpgURLRequest, "_self");
}

save.php:

$imagefile=''.$imageURL.'';
$fp = fopen($imagefile, 'wb');
fwrite($fp, $GLOBALS['HTTP_RAW_POST_DATA']);
fclose($fp);

header('Location: https://www.url.com/your-image.php');

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-08-09 00:33

After a lot of searching on the pepperflash issue and trying different methods it seems the following simple change works:

replace:

var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");

with:

var header:URLRequestHeader = new URLRequestHeader("Content-type","text/plain");

This now works on Chrome and still on all other browsers

Hope this helps anyone else

查看更多
登录 后发表回答