from requests_toolbelt import *
m = MultipartEncoder(fields={'file': ('filename',open(f, 'rb'))},
boundary='---------------------------7de1ae242c06ca'
)
import time
def my_callback(monitor):
# Your callback function
print monitor.bytes_read
m = MultipartEncoderMonitor(m, my_callback)
req_headers = {'Content-Type': m.content_type,
'path':'2016/07/09/5ASD5SDFASDFASDF/{}.zip'.format(time.time()),}
r = requests.post(url, data=m, headers=req_headers)
Using an extension library, requests_toolbelt can perfectly solve 2 problems
The building owner uses the streaming upload of requests. Here are some instructions
Streaming Uploads
Requests supports streaming uploads, which allow you to send large streams or files without reading them into memory. To stream and upload, simply provide a file-like object for your body:
with open('massive-body', 'rb') as f:
requests.post('http://some.url/streamed', data=f)
Using an extension library, requests_toolbelt can perfectly solve 2 problems
The building owner uses the streaming upload of requests.
Here are some instructions
Streaming Uploads
Requests supports streaming uploads, which allow you to send large streams or files without reading them into memory. To stream and upload, simply provide a file-like object for your body:
http://www.python-requests.org/en/master/user/advanced/#streaming-uploads
It is recommended that you use the poster module
https://atlee.ca/software/poster/