Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 230663

VappTemplate uploadFile(String fileName, InputStream is, long startByte, long endByte) fails to complete VMDK file upload

$
0
0

Hi,

 

I'm trying to use the uploadFile() API in the VappTemplate class to upload large VMDK files in chunks so I can determine and report upload progress over the entire upload time using monitorUpload().  I'm able to upload over 99% of the VMDK file, however, the final chunk is only partially uploaded and will not correctly upload all final bytes of the file.  I'm unable to determine why this is the case. 

 

Here is what the code looks like:

 

UploadVAppTemplateParamsType vappTemplParams = new UploadVAppTemplateParamsType();

vappTemplParams.setDescription("this is a test vApp Template");

vappTemplParams.setName("test vApp Template");

VappTemplate vappTemplate = vdc.createVappTemplate(vappTemplParams);

 

//standard OVF file upload completed here with:  vappTemplate.uploadOVFFile() and while (!vappTemplate.getResource().isOvfDescriptorUploaded())...

 

//now upload the large VMDK file in chunks:

 

File vmdkFile = new File("c:\\path-to\\system.vmdk");

InputStream vmdkStream = new FileInputStream(vmdkFile);

 

long byteEnd;

long byteStart = 0;       

 

//keep uploading until we reach end of stream

while (vmdkStream.available() > 0)

{

     //if the last byte will go beyond the last byte, file length - 1, then file length - 1 is our last byte, otherwise it is the next full buffer size

     //UPLOAD_BUF_SIZE_BYTES is 8 MB = 8 * 1024 * 1024

    byteEnd = (byteStart + UPLOAD_BUF_SIZE_BYTES) >= vmdkFile.length() ? vmdkFile.length() - 1 : byteStart + UPLOAD_BUF_SIZE_BYTES;

   

    //upload the chunk

    vappTemplate.uploadFile("system.vmdk", vmdkStream, byteStart, byteEnd);

  

    //get current progress

    vappTemplate = VappTemplate.getVappTemplateByReference(vcloudClient, vappTemplate.getReference());

    FileType vmdkFileType = vappTemplate.monitorUpload().get("system.vmdk");

    System.out.println("Uploaded " +  vmdkFileType.getBytesTransferred() + " bytes, " + ((1.0 * vmdkFileType.getBytesTransferred()) / vmdkFileType.getSize()) * 100.0 + "%");

  

    //start byte at next chunk

    byteStart = byteEnd;

}

 

vmdkStream.close();

 

//while (vappTemplate.getResource().getStatus() != 8) {} loop with sleep, retrieving the vappTemplate and printing the status output of the vmdk file.

 

 

Output end with progress up continuously showing something like:

 

Uploaded 649032704 bytes, 99.90290604110416%

 

This byte size is in the middle of the last chunk uploaded but fails to upload all of it.  Any suggestions on why the last 8 MB chunk cannot be fully uploaded? 


Viewing all articles
Browse latest Browse all 230663

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>