This example shows how to upload a file from a URL to a library item. The example is based on the code in the ContentLibraryWorkflow.java sample file. The sample resource is located in the vCloud Suite SDK for Java directory, client/samples/java/com/vmware/vcloud/suite/samples/interop.

This example uses the steps that are described in the Upload a File from a URL to a Library Item procedure.

...
import com.vmware.content.library.item.UpdateSession;
import com.vmware.content.library.item.UpdateSessionModel;
import com.vmware.content.library.item.updatesession.File;
import com.vmware.content.library.item.updatesession.FileTypes;
...
 
// Create a new library item. See Create an Empty Library Item. 
 
...
 
// Access the com.vmware.content.library.item.updatesession.File 
// and the UpdateSession services by using the vCloud Suite Endpoint.
   File uploadFileService = serviceManager.getVapiService(File.class);
   UpdateSession uploadService= serviceManager.getVapiService(UpdateSession.class);

// Create an UpdateSessionModel instance to track the changes you make to the item.
        UpdateSessionModel updateSessionModel = new UpdateSessionModel();
        updateSessionModel.setLibraryItemId(newItem);

// Create a new update session. 
        String clientToken = UUID.randomUUID().toString();
        String sessionId = uploadService.create(clientToken, updateSessionModel);

// Create a new AddSpec instance to describe the properties of the file to be uploaded.
         FileTypes.AddSpec fileSpec = new AddSpec();
         fileSpec.setName("ESXi patch as of 10/2/2015");
         fileSpec.setSourceType(SourceType.PULL);

// Specify the location from which the file is uploaded to the library item.
         TransferEndpoint endpoint = new TransferEndpoint();
         endpoint.setUri(URI.create("http://www.acme.com/patches_ESXi55/ESXi_patch.iso"));
         fileSpec.setSourceEndpoint(endpoint);
         uploadFileService.add(sessionId, fileSpec);

// Mark the session as completed. 
         uploadService.complete(sessionId);