Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Programmatically import documents into a dataset using DocumentServiceClient.ImportDocuments

I am trying to import documents into a dataset using DocumentServiceClient.ImportDocuments().  There are many examples of how to make the actual call (see code snippet below).  What I don't understand is where do I specify the actual documents to be imported? 

My understanding is that the dataset specified is the dataset I am importing the documents INTO.  But how does it know WHICH documents to import? 

I would expect to point it to another dataset containing the documents to be imported, or to provide a collection/list of some sort containing the documents, or point to a location on my hard drive, maybe.

Am I missing something here?

Thanks!

 

DocumentServiceClient dsClient = new DocumentServiceClientBuilder()
{
    Endpoint = $"{locationId}-documentai.googleapis.com"
}.Build();
ImportDocumentsRequest importDocumentsRequest = new ImportDocumentsRequest()
{
    DatasetAsDatasetName = DatasetName.FromProjectLocationProcessor(projectId, locationId, processorId),
    BatchDocumentsImportConfigs =
    {
        new ImportDocumentsRequest.Types.BatchDocumentsImportConfig()
    }
};
// Make the request
Operation<ImportDocumentsResponse, ImportDocumentsMetadata> importDocumentsResponse = dsClient.ImportDocuments(importDocumentsRequest);
// Poll until the returned long-running operation is complete
Operation<ImportDocumentsResponse, ImportDocumentsMetadata> completedResponse = importDocumentsResponse.PollUntilCompleted();
// Retrieve the operation result
ImportDocumentsResponse result = completedResponse.Result;
// Or get the name of the operation
string operationName = importDocumentsResponse.Name;
// This name can be stored, then the long-running operation retrieved later by name
Operation<ImportDocumentsResponse, ImportDocumentsMetadata> retrievedResponse = dsClient.PollOnceImportDocuments(operationName);
// Check if the retrieved long-running operation has completed
if (retrievedResponse.IsCompleted)
{
    // If it has completed, then access the result
    ImportDocumentsResponse retrievedResult = retrievedResponse.Result;
}

 

1 2 320
2 REPLIES 2