Uploading An Image As A ByteArray to a Blob using AS3 & AMFPHP

159 views Asked by At

I'm currently having a bit of an issue when I try to upload a photo taking using an iOS camera to a MySQL database using PHP and unfortunately have been unable to find the right help online.

Basically The User takes a photo on their iOS device and I take that raw MediaPromise and put it into a ByteArray. I then call a PHP function using AMFPHP to add the binary to a Blob in my database. But when I test the whole thing, it never seems to work. Could somebody maybe help me with this problem or at least point me in the right direction? It would be highly appreciated. Here's the code:

AS3:

var dataSource:IDataInput;

function imageSelected1(event:MediaEvent) {


var imagePromise:MediaPromise = event.data;
dataSource = imagePromise.open();

 if( imagePromise.isAsync )  {
var eventSource:IEventDispatcher = dataSource as IEventDispatcher; 
   eventSource.addEventListener( Event.COMPLETE, onDataComplete );

}
  else {
        readMediaData();
  }

    }

// PHP Connection //

// Database //
var gw2:NetConnection = new NetConnection();
gw2.connect(connectiongoeshere);


    // Responder //
var pictureresponder:Responder = new Responder(onpicture);



    function onpicture(pictureobj:Object) {
        gotoAndStop(1);

}


 function onDataComplete( event:Event ):void {
   readMediaData();
  }


        function readMediaData() {

                   var imageBytes:ByteArray = new ByteArray();
                   //dataSource.readBytes( imageBytes );

                   dataSource.readBytes(imageBytes);


                gw2.call("class.setData", pictureresponder, imageBytes);

                }

PHP:

    function setData($ba) {
       // Connecting to the database //


mysql_pconnect("hi", "hi", "hi");
mysql_select_db("hi");

 $result = mysql_query("UPDATE users set profilepicture2 ='$ba->data' WHERE email= '[email protected]'");
return $result;

}
0

There are 0 answers