【发布时间】:2013-12-11 10:53:21
【问题描述】:
我有一段 Python 代码,它可以获取正确的 url 来自 Amazon S3 的权限并将其复制到本地目录文件:
def fileDownload(self, some_Id, localDir, name, range=None):
# [...] something happens here
# get the Amazon URL
fileUrl = we_get_the_amazon_url_here
req = urllib2.urlopen(fileUrl)
if len(range):
req.headers['Range']='bytes=%s-%s' % (range[0], range[1])
# Do the download
with open(os.path.join(localDir,name), 'wb') as fp:
shutil.copyfileobj(req, fp)
return 1
我不熟悉 urllib2 但我想做的就是转
这个fileDownload方法变成了fileStreaming方法,这样我
可以将文件的结果内容通过管道传输到下游的工具中。
任何想法如何做到这一点?
【问题讨论】: