1

I would like to use Flash to send a ByteArray (of a PNG image) to a php file, in a facebook application. Is there a way to do this by sending the ByteArray as just one POST variable instead of as the entirety of the POST data?

There was a nearly identical question here: How can I send a ByteArray (from Flash) and some form data to php? but the problem is different; instead of smuggling other variables in other parts of the request, the image itself has to be sent as just a variable because Facebook commandeers the post data and puts in its own junk.

Is this at all possible? If not, can I send the image in some form other than a byteArray?

Community
  • 1
  • 1
Lack
  • 1,625
  • 1
  • 17
  • 29

1 Answers1

0

I think the easiest way is base64 encoding the image before sending it. Then it's just a string and it's safe to pass it as a regular POST variable.

On the php side, you just have to base64_decode this string and then you have your image data ready to save it to file or whatever you need (you could also feed it to GD or other such library if you need to manipulate it first).

Another option, at least in theory is using multipart/data, just like you'd use in an html form to send a file, but if I recall correctly, the player does not allow to send files using this method (until version 9.0.124 or something like that, this was possible).

So, base64 is easy and simple and it only adds some overhead; 1/3 of the file payload in terms of size and some processing time as weel, but in most cases this isn't a big deal.

Juan Pablo Califano
  • 12,213
  • 5
  • 29
  • 42
  • Thank you, it works. I used this class for base64: http://code.google.com/p/as3crypto/source/browse/trunk/as3crypto/src/com/hurlant/util/Base64.as – Lack Dec 19 '10 at 14:15