This example uses the code in the content_library_workflow.py sample file. The sample resource is located in the following vCloud Suite SDK for Python directory, client/samples/java/com/vmware/vcloud/suite/samples/workflow.

This example uses the steps that are described in the Download Files to a Local System from a Library Item procedure.

from com.vmware.content.library import item_client
from com.vmware.content.library.item import download_session_client
import os
import uuid
import urllib2
import time
 
# 1 - Create a new download session model.
download_session_model = item_client.DownloadSessionModel()
download_session_model.library_item_id = my_library_item_id
download_session_stub = item_client.DownloadSession(my_stub_config)
idem_token = str(uuid.uuid4())
download_session_id = download_session_stub.create(create_spec=download_session_model,
client_token=idem_token)
 
# 2 - Access the File service and retrieve the files you want to export.
download_session_file_stub = download_session_client.File(my_stub_config)
file_infos = download_session_file_stub.list(download_session_id)
for file_info in file_infos :
  download_session_file_stub.prepare(download_session_id, file_info.name)
 
# 3 - Wait until the file is in the prepared state before downloading.
  download_info = download_session_file_stub.get(download_session_id, file_info.name)
  while (DownloadSessionFile.PrepareStatus.PREPARED != download_info.status) :
  time.sleep(30)
 
# 4 - Download the file with an HTTP GET request.
  response = urllib2.urlopen(download_info.download_endpoint.uri)
  file_path = os.path.join(my_directory, file_info.name)
  with open(file_path, ’wb’) as f :
  f.write(response.read())
 
# 5 - Delete the download session after all files are downloaded.
download_session_stub.delete(download_session_id)