Created
January 16, 2011 16:45
-
-
Save Stanley/781937 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require('http'), | |
couchdb = http.createClient(5984, 'localhost'), | |
uuid = require('node-uuid'); | |
var id = uuid().replace(/-/g, ''); | |
var request = couchdb.request('PUT', '/test/'+id +'?batch=ok', { | |
"host": "localhost", | |
"Content-Type": "multipart/related;boundary=\"frontier\"" | |
}); | |
var content = new Buffer("kolor:\r\nŻółty"); | |
var doc = {foo: "bar"}; | |
doc._attachments = { | |
'test.txt': { | |
'follows': true, | |
'content_type': 'text/plain', | |
'length': content.length | |
} | |
} | |
request.end( | |
"--frontier\r\n" + | |
"content-type: application/json\r\n" + | |
"\r\n" + | |
JSON.stringify(doc) + | |
"\r\n--frontier\r\n" + | |
"\r\n" + | |
content + | |
"\r\n--frontier--" | |
); | |
request.on('response', function (response) { | |
console.log('STATUS: ' + response.statusCode); | |
console.log('HEADERS: ' + JSON.stringify(response.headers)); | |
response.setEncoding('utf8'); | |
response.on('data', function (chunk) { | |
console.log('BODY: ' + chunk); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment