michael
michael

Reputation: 1160

How to send a "multipart/related" content type in Actionscript?

If I want to send the following format body in actionscript through http Post:

Content-Type: multipart/related; boundary="END_OF_PART"
Content-Length: 423478347
MIME-version: 1.0

Media multipart posting
--END_OF_PART
Content-Type: application/atom+xml

<entry xmlns='http://www.w3.org/2005/Atom'>
  <title>plz-to-love-realcat.jpg</title>
  <summary>Real cat wants attention too.</summary>
  <category scheme="http://schemas.google.com/g/2005#kind"
    term="http://schemas.google.com/photos/2007#photo"/>
</entry>
--END_OF_PART
Content-Type: image/jpeg

...binary image data...
--END_OF_PART--

How can I write the actionscript to send the "multipart/related" content type.
Please advice. Thanks.

Upvotes: 1

Views: 1217

Answers (2)

mattbilson
mattbilson

Reputation: 568

Inspirit's MultipartURLLoader will probably help. Haven't used it for multipart/related, but it has lots of useful functionality for adding files with different content types.

For example, you can add files with different content types using the addFile function :

addFile(fileContent:ByteArray, fileName:String, dataField:String = 'Filedata', contentType:String = 'application/octet-stream')

It seems to use multipart/form-data when it sends :

urlRequest.requestHeaders.push( new URLRequestHeader('Content-type', 'multipart/form-data; boundary=' + getBoundary()) );

but you could easily extend this to use multipart/related.

Upvotes: 1

Myk
Myk

Reputation: 6215

One thing that might help is using something like the AS3 HTTPClient library - they have helper methods for all sorts of request/response header manipulation that plain AS3 won't do. You can find it here: http://code.google.com/p/as3httpclientlib/

Doing anything beyond simple HTTP get/post is always a pain in Flash, and multipart POST is particularly tricky. If that httpclient doesn't do what you need let me know and I have one more utility I used to do this in the past. I can dig that up for you if you need it, just let me know!

Hope that helps, myk

Upvotes: 1

Related Questions