2017-08-03 60 views
0

我使用requests.get,但它正在我执行文件的机器上下载文件,有没有办法跳过这个?我如何直接从URL到Azure Blob获取数据

r = requests.get(url,stream=True) 
    file_name = url.split("/")[-1] 
    with open(file_name, 'wb') as data: 
     for chunk in r.iter_content(chunk_size = 1024*1024): 
      if chunk: 
       data.write(chunk) 
    block_blob_service.create_blob_from_path(path.join(container,blob), 
          data.name, 
          file_name , 
          content_settings=ContentSettings(content_type=mimetypes.guess_type('./%s' %url.split("/")[-1])[0])) 
+0

https://docs.microsoft.com/en-us/azure/storage/storage-python-how-to-use-blob-storage – diek

回答

0

尝试使用以下代码。

r = requests.get(url,stream=True) 
block_blob_service.create_blob_from_stream(container_name, blob_name, io.BytesIO(r.content)) 

或者

r = requests.get(url,stream=True) 
block_blob_service.create_blob_from_bytes(container_name, blob_name, r.content) 

希望它能帮助。