There's one problem with using URLVariables: it works on NUL-terminated
strings, so if you happen to have a 0 in the compressed data, it will be
truncated

Some time ago I wrote a class to post data in multipart format (basically,
it does the same the browser does when you have a form with a file input). I
used it to send image files, but since the data is binary, it shouldn't
matter what kind of file you're sending.

So, from the php side you handle it much like an oridnary html form. Text
variables will be put in $_POST, and the "files", i.e. the binary data,
would be in $_FILES.


I had uploaded that class to pastebin and it's still there:
http://pastebin.com/f11a897cf


I'm re-pasting a use example from another email:


=====>

 An example of use (it's a copy & paste from some worting code, just to give
you an idea):


import ar.com.califa010.utils.FormData;

   // getEncodedImg() is a method that returns a JPG as a byteArray

   var rawJpg:ByteArray = getEncodedImg();
   var formData:FormData = new FormData();

   var imageMimeType:String = FormData.JPG_FILE;
   var fileName:String = "imageFile.jpg";


   // from the php side, you'll get this data with $_FILES['imageFile']
   // rawJpg is the byteArray you want to send
   // fileName and imageMimeType don't really matter that much
   // it's supposed to send the name of the original file and the type to
hint the server, but
   // I think you can leave it as is and will have no problems

   formData.addFile("imageFile", rawJpg, fileName, imageMimeType);


   formData.addField("sFormat",imgFormat);
   formData.addField("idImagen",_idImagen);

   var req:URLRequest  = new URLRequest(url);

   req.method   = "POST";
   req.contentType  = formData.contentType;
   req.data   = formData.getPostData();

   var loader:URLLoader = new URLLoader();
   configureListeners(loader);

    loader.load(req);
 =====>

Cheers
Juan Pablo Califano

2008/10/3, Benny <[EMAIL PROTECTED]>:
>
> We are getting closer ;-)
>
> The code you provided worked for me too.
> When I compare my code to yours I notice that I am using the $_POST array
> while you are using the PHP input stream. The other major difference is the
> fact that I am POSTing using via an URLVariables instance.
>
> When I change both in my code then everything indeed works fine.
>
> The only problem now is that in the production code I have to send several
> ByteArray objects to the server in one go. And I have to process them
> separately in the PHP script. Hence I thought the obvious thing would be to
> assign the various vars to an URLVariables object and send that as the
> URLRequest data. On the PHP side I wanted then to access those vars again
> as
> members of the $_POST array and gzinflate the compressed vars there for
> further processing.
>
> Can you think of any solution that would make this possible?
>
> The only thing which comes to my mind at the moment is parsing the php
> input
> string by hand but I still would expect that the $_POST array should just
> work too, after all it seems it contains the correct compressed string. But
> when I feed that string to the gzinflate function I get an empty string in
> return and when I feed it the exact same string hardcoded then it returns
> the correct uncompressed string... I must be missing something obvious ;-)
>
> _______________________________________________
> Flashcoders mailing list
> Flashcoders@chattyfig.figleaf.com
> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to