[英]Upload generated big file with python
Is there a possibility to upload really big data using python? 有可能使用python上传真正的大数据吗?
For example to upload 100GB I can use requests module like: 例如,要上传100GB,我可以使用请求模块,例如:
with open('really_big_file') as f:
requests.post('http://some.url/streamed', data=f)
Problem that I haven't got any file. 我没有任何文件的问题。 I need to generate some random data and upload it to server.
我需要生成一些随机数据并将其上传到服务器。 Something like this:
像这样:
while uploaded_size < required_size:
data = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(1000))
requests.post('http://some.url/chunk', data)
uploaded_size += 1000
Problem with this code that it will upload many small files, while I need to upload one big file. 此代码存在问题,它将上传许多小文件,而我需要上传一个大文件。 Also I tried to generate data with function:
我也尝试生成具有功能的数据:
def gen():
while uploaded_size < required_size:
data = ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(1000))
uploaded_size += 1000
yield data
requests.post('http://some.url/chunked', data=gen())
This variant will throw error: Broken pipe 此变体将引发错误:管道损坏
I would very appreciate if you will say where is my mistake or what module I should try. 如果您能说出我的错误在哪里或应该尝试哪个模块,我将不胜感激。
UPD: Resolved with sockets UPD:解决与套接字
requests.post('http://some.url/chunked', data=''.join(gen()))
gen()
returns an iterator. gen()
返回一个迭代器。 you should iterate over it to get the values. 您应该对其进行迭代以获得值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.