2017-08-03 61 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) 

希望它能幫助。