How to Autodetect Content Type and Validate using Java

It’s impossible to trust information coming from the client side of an application. That’s one reason why document validation is so important online; it’s critical to ensure any new information/documents uploaded to your website by a user meets the proper criteria to fulfill a request. Thankfully, there’s an API for that: our Autodetect Content Type & Validate API will (as the title suggests) automatically determine the type of input content received and verify if that the content is valid at depth. Afterward, it’ll report the validation result. In the event there was an error with a document, you’ll receive an error description & error path along with some additional information.

To help you take advantage of this API, we’ve provided ready-to-run code examples you can use to structure your API call in Java, along with instructions to make it as easy & efficient as possible.

Without further ado, let’s begin installing Maven by adding a reference to the repository in pom.xml:


Next, add one to the dependency in pom.xml:


Now you can add in the import classes and call the API. Only two parameters are required here; those include your input file, and your Cloudmersive API key (obtainable by visiting our website and registering a free account).

// Import classes:
//import com.cloudmersive.client.invoker.ApiClient;
//import com.cloudmersive.client.invoker.ApiException;
//import com.cloudmersive.client.invoker.Configuration;
//import com.cloudmersive.client.invoker.auth.*;
//import com.cloudmersive.client.ValidateDocumentApi;
ApiClient defaultClient = Configuration.getDefaultApiClient();// Configure API key authorization: Apikey
ApiKeyAuth Apikey = (ApiKeyAuth) defaultClient.getAuthentication("Apikey");
Apikey.setApiKey("YOUR API KEY");
// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
ValidateDocumentApi apiInstance = new ValidateDocumentApi();
File inputFile = new File("/path/to/inputfile"); // File | Input file to perform the operation on.
try {
AutodetectDocumentValidationResult result = apiInstance.validateDocumentAutodetectValidation(inputFile);
} catch (ApiException e) {
System.err.println("Exception when calling ValidateDocumentApi#validateDocumentAutodetectValidation");



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.