Example of http.Client sending "multipart/form-data"?

2,925 views
Skip to first unread message

AJ ONeal

unread,
Dec 10, 2010, 2:26:43 PM12/10/10
to node.js mailing list
Does anyone have an example of or module for uploading binary files using http.Client?

My google searches keep showing node-formidable, I'm looking for client code, not server code.

AJ ONeal

cwolves

unread,
Dec 12, 2010, 10:03:51 PM12/12/10
to nodejs
It's pretty simple to implement from scratch. I haven't done it in
node yet, but have in other languages.

The specs: http://www.w3.org/Protocols/rfc1341/7_2_Multipart.html

The gist is that you just post something like this:


MIME-Version: 1.0
Content-type: multipart/mixed; boundary="gc0p4Jq0M2Yt08jU534c0p"
--gc0p4Jq0M2Yt08jU534c0p--
Content-Type: application/octet-stream
Content-Transfer-Encoding: base64

put base64 encoded data here


boundary can be whatever, but the string --boundary-- should NOT exist
in the file contents, so a guid is good to use.

-Mark

mscdex

unread,
Dec 13, 2010, 2:02:11 AM12/13/10
to nodejs
On Dec 12, 10:03 pm, cwolves <cwol...@gmail.com> wrote:
> boundary can be whatever, but the string --boundary-- should NOT exist
> in the file contents, so a guid is good to use.

Why would that matter if it's base64 encoded?

Dean Landolt

unread,
Dec 13, 2010, 3:19:34 PM12/13/10
to nod...@googlegroups.com
It wouldn't. In fact, base64 encoding completely defeats the purpose of multipart.

AJ ONeal

unread,
Jan 7, 2011, 3:09:42 AM1/7/11
to node.js mailing list
I did manage to get a working example up here:

https://github.com/coolaj86/node-examples-coolaj86/blob/master/http-upload.js

AJ ONeal

AJ ONeal

unread,
Jan 13, 2011, 5:30:40 PM1/13/11
to node.js mailing list
And another based on FileAPI and FormData:

Paired Client / Server upload example:
https://github.com/coolaj86/node-file-api/blob/master/examples/upload-client.js
https://github.com/coolaj86/node-file-api/blob/master/examples/upload-server.js

I just got it up, so there will be some cleanup and the API is likely to change slightly.

Once I get it polished it will find its way into abstract-http-request
https://github.com/coolaj86/abstract-http-request

AJ ONeal
Reply all
Reply to author
Forward
0 new messages