---
title: "File validation - Signature sessions"
description: "How to validate the files users choose in Rest PKI Core signature sessions, including a file naming rule given as a regular expression."
canonical: "https://docs.lacunasoftware.com/en-us/articles/rest-pki/core/integration/signature-sessions/file-validation"
locale: "en"
product: "Rest PKI Core"
last_updated: "2026-10-12"
---

# File validation - Signature sessions

You can validate the files chosen by the user during signature sessions using the mechanisms described in this article.

## File naming rule

If you have a naming rule for the files you accept, you can configure your Rest PKI Core account to validate each file selected by the user
with a regular expression that represents your rule.

Consider a hypothetical situation in which only files whose name starts with the letter `P` or `X`, followed by 6 digits and the `.pdf`
extension, are accepted. To enforce this condition, the naming rule would be configured as:

```plaintext
^[PX]\d{6}\.pdf$
```

The user would then be prevented from choosing files whose names do not match this pattern:

![File rejected by pattern](https://docs.lacunasoftware.com/images/rest-pki/core/file-rejected-pattern.png)

> **Note**
>
> Our [developer support](mailto:suporte@lacunasoftware.com) can help you write the regular expression from a textual description of your
> naming rule.

## File validation API

You can also configure a file validation API, implemented by your application, to be called to validate each file chosen by the user.
Your application receives the file name (along with its *MIME type* and size in bytes) and returns whether the file should be accepted (and,
if not, the reason for the rejection).

The validation request is an HTTP `POST` request whose *payload* is a `ValidateFileRequest` object (see the
[API reference](https://core.pki.rest/swagger) for the model definition). For example:

```json
{
	"name": "P123456.pdf",
	"contentType": "application/pdf",
	"length": 2476032
}
```

Your application must respond with a `ValidateFileResponse`, as below:

```json
{
	"accept": true,
	"rejectReason": null
}
```

Or, if the file is rejected:

```json
{
	"accept": false,
	"rejectReason": "Message to the user"
}
```

The message returned by your application is shown to the user, for example:

![File rejected by API](https://docs.lacunasoftware.com/images/rest-pki/core/file-rejected-api.png)

**Demos and samples**

- Validate files uploaded to a Rest PKI Core signature session: [.NET](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/dotnet/mvc/PkiSuiteAspNetMvcSample/Controllers/ValidateFileRestCoreController.cs) · [Java](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/java/springmvc/src/main/java/com/lacunasoftware/pkisuite/controller/ValidateFileRestCoreController.java) · [PHP](https://github.com/LacunaSoftware/PkiSuiteSamples/blob/master/php/plain/public/validate-file-rest-core/index.php)
