How to submit a multipart form

10 views
Skip to first unread message

Gonzalo

unread,
Aug 7, 2008, 10:30:03 PM8/7/08
to AS3 HttpClient
Hi guys:
I was trying to submit a multipart form doing something like this:

var request:HttpRequest = new Post();
var filePart:Part = new Part(HttpFileStream.readFile(file),
"application/octet-stream", [{ name: "srcfile", value: file.name }]);
request.setFormData(variables);
request.multipart = new Multipart([filePart]);
_httpClient.request(new URI(END_POINT), request);

But I'm getting a 404 not found.
If I use PUT or GET there is no 404 error, but invalid method error.
Any hints?

Thanks,
--Gonzalo

gabe

unread,
Aug 8, 2008, 12:27:33 AM8/8/08
to AS3 HttpClient
Oops, it looks like multipart is a little broken :)

setFormData is for doing name1=value1&name2=value2 as the content.
Multipart sets the content using parts separated by a boundary. You
can't really use them together. The API is definitely a little
confusing in the area. I added so it throws an exception until the API
is clearer.


But I just committed some work to the multipart stuff. Can you try
this?

var multipart:Multipart = new Multipart([
new Part("name1", "value1"),
new Part("name2", "value2"),
new FilePart(file, "application/octet-stream")
]);

httpClient.postMultipart(new URI(END_POINT), multipart);


I started a test for multipart post (see test/s3/S3PostTest) and I
don't have it completely working but I plan to try to get it working
in the next week (hopefully tomorrow).

gabe

unread,
Aug 8, 2008, 1:19:07 PM8/8/08
to AS3 HttpClient
ok it looks like multipart is working now... I was able to get the S3
post test passing using raw data and from a File.

The example I gave above should work now:

var multipart:Multipart = new Multipart([
new Part("name1", "value1"),
new Part("name2", "value2"),
new FilePart(file, "application/octet-stream")
]);
httpClient.postMultipart(new URI(END_POINT), multipart);

Gonzalo

unread,
Aug 8, 2008, 8:38:24 PM8/8/08
to AS3 HttpClient
Perfect!!!
Thanks for a very fast reply and fix ^^

--Gonzalo
Reply all
Reply to author
Forward
0 new messages