Im loading images into Flash and using JPGEncoder to encode the image to a ByteArray and send this to AMF PHP which writes out the bytearray to a file. This all appears to work correctly and I can download the resulting file in Photoshop CS4 absolutely fine. When i try to open it from the desktop or open it back in Flash it doesnt work... Picasa my default image browser says "Invalid"
我将图像加载到Flash中并使用JPGEncoder将图像编码为ByteArray并将其发送到AMF PHP,后者将bytearray写入文件。这一切似乎都正常工作,我可以在Photoshop CS4中下载生成的文件绝对正常。当我尝试从桌面打开它或在Flash中打开它时它无法正常工作... Picasa我的默认图片浏览器显示“无效”
Here is the code i use to write the bytearray to a file -
这是我用来将bytearray写入文件的代码 -
$jpg = $GLOBALS["HTTP_RAW_POST_DATA"]; file_put_contents($filename, $jpg);
$ jpg = $ GLOBALS [“HTTP_RAW_POST_DATA”]; file_put_contents($ filename,$ jpg);
That's it ... I use the NetConnection class to connect and call the service, do I need to say Im sending jpg data? I assumed that JPGEncoder took care of that. How can I validate the bytearray before writing the file? Do I need to set MIME type or something?
就是这样......我使用NetConnection类来连接和调用服务,我是否需要说我发送jpg数据?我假设JPGEncoder处理了这个问题。如何在写入文件之前验证bytearray?我需要设置MIME类型吗?
Thanks - here is some code:
谢谢 - 这是一些代码:
item.load();
function _onImageDataLoaded(evt:Event):void {
var tmpFileRef:FileReference=FileReference(evt.target);
image_loader=new Loader ;
image_loader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onImageLoaded);
image_loader.loadBytes(tmpFileRef.data);
}
function _onImageLoaded(evt:Event):void {
bitmap=Bitmap(evt.target.content);
bitmap.smoothing=true;
if (bitmap.width>MAX_WIDTH||bitmap.height>MAX_HEIGHT) {
resizeBitmap(bitmap);
}
uploadResizedImage(bitmap);
}
function resizeBitmap(target:Bitmap):void {
if (target.height>target.width) {
target.width=MAX_WIDTH;
target.scaleY=target.scaleX;
} else if (target.width >= target.height) {
target.height=MAX_HEIGHT;
target.scaleX=target.scaleY;
}
}
function uploadResizedImage(target:Bitmap):void {
var _bmd:BitmapData=new BitmapData(target.width,target.height);
_bmd.draw(target, new Matrix(target.scaleX, 0, 0, target.scaleY));
var encoded_jpg:JPGEncoder=new JPGEncoder(90);
var jpg_binary:ByteArray=encoded_jpg.encode(_bmd);
_uploadService=new NetConnection();
_uploadService.objectEncoding=ObjectEncoding.AMF3
_uploadService.connect("http://.../amfphp/gateway.php");
_uploadService.call("UploadService.receiveByteArray",new Responder(success, error), jpg_binary, currentImageFilename);
}
1 个解决方案
#1
Your problem is in your PHP service. In AMFPHP the POST data is abstracted, so what you need in your AMFPHP UploadService script is a function that accepts the two input arguments in your _uploadService.call --jpg_binary and currentImageFilename-- like this:
您的问题出在您的PHP服务中。在AMFPHP中,POST数据是抽象的,因此您在AMFPHP UploadService脚本中需要的是一个函数,它接受_uploadService.call --jpg_binary和currentImageFilename中的两个输入参数 - 如下所示:
<?php
class UploadService {
function receiveByteArray( $ba, $filename ) {
$result = file_put_contents($filename, $ba->data);
if ( $result == FALSE ) {
trigger_error( "File save failed" );
}
}
}
?>
#1
Your problem is in your PHP service. In AMFPHP the POST data is abstracted, so what you need in your AMFPHP UploadService script is a function that accepts the two input arguments in your _uploadService.call --jpg_binary and currentImageFilename-- like this:
您的问题出在您的PHP服务中。在AMFPHP中,POST数据是抽象的,因此您在AMFPHP UploadService脚本中需要的是一个函数,它接受_uploadService.call --jpg_binary和currentImageFilename中的两个输入参数 - 如下所示:
<?php
class UploadService {
function receiveByteArray( $ba, $filename ) {
$result = file_put_contents($filename, $ba->data);
if ( $result == FALSE ) {
trigger_error( "File save failed" );
}
}
}
?>