This example shows how to upload a file from a URL to a library item.
This example uses the steps that are described in the Upload a File from a URL to a Library Item procedure.
use Com::Vmware::Content::Library; use Com::Vmware::Content::Library::Item; use Com::Vmware::Content::Library::Item::Updatesession; use Data::GUID; # 1 - Create a new library item to hold the uploaded file. my $item_model = new Com::Vmware::Content::Library::ItemModel(); $item_model->set_name('ESXi patches'); $item_model->set_description('ESXi 5.5 security patches as of 2/3/2015'); $item_model->set_type('iso'); $item_model->set_library_id($my_library_id); my $idem_token = Data::GUID->guid_string; my $item_stub = new Com::Vmware::Content::Library::ItemService($my_stub_config); $my_library_item_id = $item_stub->create(create_spec => $item_model, client_token => $idem_token); # 2 - Create an UpdateSessionModel instance to track your changes to the item. my $update_session_model = new Com::Vmware::Content::Library::Item::UpdateSessionModel(); $update_session_model->set_library_item_id($my_library_item_id); # 3 - Create an update session from the model. $idem_token = Data::GUID->guid_string; my $update_session_stub = new Com::Vmware::Content::Library::Item::UpdateSession($my_stub_config); my $update_session_id = $update_session_stub->create(create_spec => $update_session_model, client_token => $idem_token); # 4 - Create a new AddSpec instance to describe the properties of # the file to be uploaded. my $file_spec = new Com::Vmware::Content::Library::Item::Updatesession::File::AddSpec(); $file_spec->set_name('ESXi patch as of 10/2/2015'); $file_spec->set_source_type( Com::Vmware::Content::Library::Item::Updatesession::File::SourceType::PULL); # 5 - Specify the location from which the file is to be uploaded. my $endpoint = new Com::Vmware::Content::Library::Item::TransferEndpoint(); $endpoint->set_uri('http://www.example.com/patches_ESXi55/ESXi_patch.iso'); $file_spec->set_source_endpoint($endpoint); # 6 - Link the file specification to the update session. my $update_file_stub = new Com::Vmware::Content::Library::Item::Updatesession::File( $my_stub_config); $update_file_stub->add(update_session_id => $update_session_id, file_spec => $file_spec); # 7 - Mark session as completed, to initiate the asynchronous transfer. $update_session_stub->complete(update_session_id);