This example shows how to copy library item files to the client system, using an HTTP transfer.
This example uses the steps that are described in the Download Files to a Local System from a Library Item procedure.
use Com::Vmware::Content::Library::Item; use Com::Vmware::Content::Library::Item::Downloadsession; use Data::GUID; use File::Fetch; # 1 - Create a new download session model. my $download_session_model = new Com::Vmware::Content::Library::Item::DownloadSessionModel(); $download_session_model->set_library_item_id($my_library_item_id); my $download_session_stub = new Com::Vmware::Content::Library::Item::DownloadSession($my_stub_config); my $idem_token = Data::GUID->guid_string; my $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. my $download_session_file_stub = new Com::Vmware::Content::Library::Item::Downloadsession::File($my_stub_config); my @file_infos = $download_session_file_stub->list($download_session_id); foreach my $info (@file_infos) { my $info_name = $info->get_name(); $download_session_file_stub->prepare($download_session_id, $info_name); # 3 - Wait until the file is in the prepared state before downloading. my $download_info = $download_session_file_stub->get($download_session_id, $info_name); sleep 30 until $download_info->get_status == Com::Vmware::Content::Library::Item::Downloadsession::File::PrepareStatus::PREPARED # 4 - Download the file with an HTTP GET request. my $uri = $download_info->get_download_endpoint(); my $ff = File::Fetch->new(uri => $uri); my $file = $ff->fetch(to => '/tmp'); print "\nDownloaded $file."; # 5 - Delete the download session after all files are downloaded. } # foreach $info $download_session_stub->delete($download_session_id); print "\n\nCompleted download session $download_session_id.\n"