This content has been marked as final. Show 11 replies
it's easier in as3 because data transmission (using the URLLoader class) is native.
@kglad: I'm not sure that I understand. URLLoader would presumably be used for the response from a form submission... which I don't have a problem with in as2.
I would think the as3 equivalent (having just checked the docs, because I haven't played with as3 enough yet) would be an alternate version of URLVariables (ie. one that doesn't use url-encoded querystring style, but uses multipart/form-data style encoding) and the appropriate contentType setting for the URLRequest. All these 3 classes seem to overlap in LoadVars for as2, they're separate in as3 . And more capable in as3 because you can transfer binary data. That's the only difference I can see with LoadVars.
I'll see how I can get on with LoadVars. I might have to go to as3 for this bit if I get stuck.
the URLLoader class has a dataFormat property that can be assigned to "binary".
Yes, I understand that... but URLLoader is for downloading, not submitting/uploading so is not specifically relevant to my needs here (it would be needed to accept the response from the server same as a regular html form submission - which I am also doing in flash).
The parallel in as3 for what I want is URLRequest for which (as far as I can see) the only difference cf. LoadVars... is that it also allows raw binary submission/upload. But I think the only time that I would need this is if the site requires a file upload in the form. And I don't think I can directly emulate that as part of a multipart form submission from flash - I think I'd have to change the php to handle it separately, if I was doing it from flash (I assume with as3 there's still no way to load a local bitmap directly into flash in order to access its byteArray?).
Overall what I'm trying to do is probably best done using ajax and iframes etc to do progressive upgrades to the html - I know it can be done that way. I'm just trying to see if I can do it in flash.
for sending binary data the URLLoader class can still be used and, in fact, is used in jpegencoder to send (jpeg) data to a server or client computer.
URLRequest is used with every URLLoader (and Loader).
I know... but the URLLoader is for the server response. I mentioned above I would need it but that its not specifically relevant because the encoding of the response is not a problem. The encoding of the submission is.
The URLRequest is for the request to the server (and yes its data can be binary). That's all this is about. In as2 it means I don't want to send url-encoded like: name=value&name2=value2;
I want to send something like:
"Content-Disposition: form-data; name="name"
"Content-Disposition: form-data; name="name2"
with contentType='mutipart/form-data ;boundary="boundaryMarker"
in the headers.
I've worked out how to do this in as2. I would only need as3 if I had binary content to send I think.
that is encoding the submission: it's sending binary data to a server-side php file.
I know its encoding, lol -that's the class I'm writing (its not complicated it just needs to be correct in terms of what it generates). Its multipart/form-data encoding (which does permit some 'parts' to be binary data).
But you can't send raw binary using LoadVars in as2 -unless I've missed something - it requires using some other encoding (base64 or whatever) .
Using LoadVars/XML from what I understand you can only text-encode the data because I think for example you can't send a char code(0) - I think its an end-of-string marker and everything is dealt with as text in LoadVars.
Some of the forms include image uploads...i.e. binary chunks of data and I think that would perhaps be impossible to implement perhaps even in as3 without custom php (ie. beyond what I already have) to handle, for example, the images being uploaded separately and not part of the original multipart encoding that the browser would do. That might be different if flash could get a bytearray from a local filereference.browse... but I don't think it can unless that's something new and exciting in as3.
one or both of us is mixing the URLLoader discussion with the LoadVars discussion.
nothing i've said it relevant to LoadVars. all my statements are about the as3 URLLoader class.
i know you're working with as2, but comments were related to your initial post where you stated, "I guess this might be easier to do in as3" and i'm just trying to point out that yes, it's a lot easier.
Sorry for my part in the confusion - and please don't form the wrong impression. I certainly appreciate your replies!
But as far as I can see its not really easier. Only more flexible in terms of the potential to include binary data in the request - and I may yet need that.
There is still no native encoding for multipart/form-data in as3 as far as I can see. URLVariables is the only pre-built encoding class and its the same as LoadVars. Setting the contentType for either LoadVars (and I assume also for URLRequest) does nothing to the content itself it just tells the server how to treat it.
Here's how I did it using LoadVars in case anyone wants to do something similar. Its quick but it seems to work locally using Apache/PHP5.2- the post variables get populated using this encoding method - again there are no application/octet-stream parts possible using as2 as far as I can see so I didn't even attempt that. The test needs to be run from a browser in the site, not from flash for it to work properly.
Maybe its possible to specify other encoding types for binary data chunks e.g. base64 - I'm not so clear on that part, because I don't know how savvy the servers are in terms of handling multiple encoding types. But I think it would be better to try to do that in as3. All this does is basically nothing more than the LoadVars urlencoded data upload using the different encoding format in terms of its results, so its not that exciting.
The real challenge is that html form submission in this encoding format often includes image uploads as one or more of the 'parts'. And that's the part I don't know (think) can be done with flash because I don't think you can include a FileReference with the other data to be submitted using this method. But I don't know.