Revision 343537383731 () - Diff

Link to this snippet: https://friendpaste.com/28kxlg0FrjbOSTyDLFLbZb
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import httplib
import os

"""
snippet to upload big files in couchdb. File test is created with dd:

dd if=/dev/zero of=test4G bs=1024 count=4096000
"""

headers={
'Accept': 'application/json',
'Connection': 'keep-alive',
'Content-Type': 'application/octet-stream',
'Keep-Alive': '300',
'Content-Length': os.path.getsize('test4G')}

f = open('test4G')

conn = httplib.HTTPConnection('127.0.0.1:5984')

conn.putrequest('PUT', '/test/blah/test4G?rev=516247523',
skip_accept_encoding=True)

# Send the HTTP headers.
for header_name in headers:
conn.putheader(header_name, headers[header_name])
conn.endheaders()

# send content
while 1:
binarydata = f.read(100000)
if binarydata == '': break
conn.send(binarydata)

response = conn.getresponse()

print response.read()