How to Validate Image Files in C#
There are a surprisingly large number of viable image formats in use today — which makes validating unique image uploads a tall task for any application. Thankfully, using the code below, you can easily validate dozens of image formats (including the most common formats, such as PNG, JPG, Gif, etc.) in a single, comprehensive operation.
To take advantage of this API with C# code examples, first use the following command to get the client SDK installed:
Install-Package Cloudmersive.APIClient.NET.DocumentAndDataConvert -Version 3.4.2
Then copy & paste from the ready-to-run code below to structure your API call:
using System;
using System.Diagnostics;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Api;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Client;
using Cloudmersive.APIClient.NET.DocumentAndDataConvert.Model;
namespace Example
{
public class ValidateDocumentImageValidationExample
{
public void main()
{
// Configure API key authorization: Apikey
Configuration.Default.AddApiKey("Apikey", "YOUR_API_KEY");
var apiInstance = new ValidateDocumentApi();
var inputFile = new System.IO.FileStream("C:\\temp\\inputfile", System.IO.FileMode.Open); // System.IO.Stream | Input file to perform the operation on.
try
{
// Validate an Image File
DocumentValidationResult result = apiInstance.ValidateDocumentImageValidation(inputFile);
Debug.WriteLine(result);
}
catch (Exception e)
{
Debug.Print("Exception when calling ValidateDocumentApi.ValidateDocumentImageValidation: " + e.Message );
}
}
}
}
You can authenticate your API calls for free with a free-tier API (you can get one by registering a free account on the Cloudmersive website).