tags:

views:

31

answers:

3

I saw this post and don't understand why it's so struggling to post an image to server side with flash, or is it just the poster didn't do it in a proper manner ?

So far my progress is:

var ba:ByteArray = (new PNGEncoder()).encode(vidBmpHolder);
var request : URLRequest = new URLRequest("http://localhost:3000/doodles");
request.method = URLRequestMethod.POST;
A: 

in that post, flash is not the problem, but the serverside is.

back2dos
Not a problem,but struggling..
@user198729: Problem, struggling, what's the difference? Fact is, nothing but a space character was missing in the ridiculously long `getMultiPartRequestData` ruby-method. This is something I would expect a framework like RoR to do out of the box. Probably it even does, or at least there's a number of ruby gems ready to be plugged in, but the author didn't try.
back2dos
A: 

There are a bunch of much easier ways to send an image to the server in Flash. The user chose to make the Flash side extremely complex in order to make the server side extremely easy. Also keep in mind that the user there is sending a dynamically generated image, sending a image chosen by the user is even easier for both client and server.

The easiest way to send an image, or any data, from client to server is to use URLRequest like the other poster did but just put the image in the data field directly, none of the multipart messaging stuff. Then on the server side read the request stream and store it in it's entirety as the image. Depending on the server platform this may take more code than using a standard form post (more code as in 5-6 lines instead of 1-2). Either way, it's usually straightforward.

Other options are to use web services (bad, encodes as base64) or AMF/Remoting (not bad, but no big advantage here, but easier if it's already configured and used elsewhere).

Sam
Thanks for the tip!Which package should I import to use `PNGEncoder` ?
@user198729, `PNGEncoder` is a Flex framework class in `mx.graphics.codec`.
Sam
@user198729: alternatively, if you don't want to use flex, you can use the as3corelib encoder: http://code.google.com/p/as3corelib/source/browse/#svn/trunk/src/com/adobe/images
back2dos
@back2dos, but I met this same problem as this one when using as3corelib: http://stackoverflow.com/questions/3169831/why-is-the-bitmapdata-not-posted-to-server-side-with-flash
@user198729: Again, this has nothing to do with flash. The as3corelib certainly doesn't produce the loopback-address. PNG files always start with the bytes ‰PNG. They're not there, ergo what was dumped is not the file transmitted. The corelib is maintained by a handful of very skillful people. When you have a problem using it, it almost certainly means, you're doing something wrong. And in this case, as in the other post you linked, the problem is at the server side, so NOTHING you can do on the client side will fix the problem. Btw: I think I was able to answer the other question.
back2dos
A: 

There is an easier way to upload images using FileReference and calling its upload method specifying the URL you want to upload to. I think the post you referred to is more complicated because the poster is dynamically generating an image and then uploading it. The FileReference can only upload local image files that have been selected by user interaction.

Wade Mueller
The image I'm posting is also dynamically generated.