Add the Data

When uploading external data files, you can use the InsightsExternalDataPart object to load the data in smaller chunks.

After inserting a row into the InsightsExternalData (header) object, split your data into 10-MB chunks and upload the chunks to InsightsExternalDataPart objects. You associate the part objects with the header object by setting the InsightsExternalDataId field on the part objects to the ID of the header object. The part objects contain the bytes of data and must be assigned part numbers in a contiguous sequence, starting with 1.

Ensure that the chunks of data are smaller than 10 MB. If the data is compressed, it must be compressed first and then split into 10-MB chunks. Only the gzip format is supported.

The following example splits a file into 10-MB chunks, and then uploads the chunks to InsightsExternalDataPart objects.

List<File> fileParts = chunkBinary(dataFile); //Split the file

for(int i = 0;i<fileParts.size();i++)
{
    SObject sobj = new SObject();
    sobj.setType("InsightsExternalDataPart"); 
    sobj.setField("DataFile", FileUtils.readFileToByteArray(fileParts.get(i)));
    sobj.setField("InsightsExternalDataId", parentID);
    obj.setField("PartNumber",i+1); //Part numbers should start at 1    
    SaveResult[] results = partnerConnection.create(new SObject[] { sobj });
    for(SaveResult sv:results)
        if(sv.isSuccess())
            rowId = sv.getId();
}

For detailed information about the InsightsExternalDataPart object, see InsightsExternalDataPart.