问题
I'm having problems sending a ByteArray over to my Zend_Amf_server. I get a NetConnection.Bad.Call back from the server. If I send a variable with another datatype then ByteArray it works fine.
I used the same script before with AMFPHP witouth any problems. But for this project I really need this to work in Zend_Amf.
AS3:
var path:String = "/images/picture.jpg";
var ba:ByteArray = jpgencoder.encode(bitmap.bitmapData);
var nc:NetConnection = new NetConnection();
nc.connect(zend_amf_server);
nc.call("Service.saveJPG", new Responder(responseHandler, errorHandler), path, ba);
PHP:
class Service{
public function saveJPG($path, $byteArray){
return "worked";
}
}
回答1:
I was getting the same error from Zend AMF tonight doing basically the same thing with code that previously worked in AMF. Here's what I have that's working. The only bit I spot different from your code is I'm only passing the ByteArray to Zend, and I'm explicitly setting the ObjectEncoding.
I kept getting empty jpgs on the server because I'd read elsewhere that I needed to do ->data to get to the ByteArray data.
AS3:
_service = new NetConnection();
_service.objectEncoding = ObjectEncoding.AMF3;
_responder = new Responder(this._onSuccess, this._onError);
_service.connect(zend_amf_server);
var myEncoder:JPGEncoder = new JPGEncoder( qualityValue );
var myCapStream:ByteArray = myEncoder.encode ( myBitmapSource ); // myBitmapSource is BitmapData drawn from a Sprite
this._service.call("Remote.savePhotoToServer", this._responder, myCapStream);
PHP:
function savePhotoToServer ( $pInfos )
{
$bytearray = $pInfos;
$idimage = $this->nameImage(".jpg"); // calls a private func for a new name
return ( $success = file_put_contents("./_photos/".$idimage, $bytearray) ) ? $idimage : $success;
}
回答2:
Thanks David for your reply, the problem seemed to be that I sent a ByteArray to Zend_Amf together with a String. If I send the ByteArray only it works fine and the Image is saved.
The only problem now is that the path to save the image on should be variable and I can't send it over to my Amf_Server together with the ByteArray at the same time.
回答3:
Ok, I found the problem. I was using the Zend Framework in the latest 'tag' repository v. 1.7.5 I switched the repository for AMF to the the 'trunk' repository and now it works. There was a bug in Zend_Amf_Server when sending Arrays over to it.
来源:https://stackoverflow.com/questions/585685/sending-bytearray-to-zend-amf