A comprehensive .NET 8.0 helper library providing production-ready utilities for enterprise applications. Coject.Core.Helper streamlines common development tasks with robust implementations for file management, email services, data processing, security, and cloud integration. Key Features: - File Management: Multi-provider support (AWS S3, FTP, Local) with upload, download, and file signature validation - Email Services: Full-featured SMTP integration using MailKit with template support and signature generation - Security: Data encryption, JWT token handling, and barcode generation with ZXing - Data Utilities: JSON processing, date/time helpers, string manipulation, and image handling - Cloud Integration: Seamless AWS S3 operations with configurable storage solutions - API Integration: Helper classes for external service communication Perfect for applications requiring reliable file storage, secure email delivery, data encryption, and cloud service integration. Built with extensibility and performance in mind, this library reduces boilerplate code and accelerates development cycles. Dependencies include MailKit, MimeKit, AWSSDK.S3, System.IdentityModel.Tokens.Jwt, and ZXing.Net.Mobile for comprehensive functionality.
$ dotnet add package Coject.Core.HelperA comprehensive .NET helper library providing essential utilities for file management, email operations, SMS services, data handling, encryption, and integration with cloud services.
Coject.Core.Helper is a production-ready utility library designed to streamline common development tasks in .NET applications. It offers robust implementations for file operations with advanced validation, email services, SMS integration, data manipulation, security features, and multiple storage provider support.
Install via NuGet Package Manager:
dotnet add package Coject.Core.HelperOr via Package Manager Console:
Install-Package Coject.Core.HelperAdd the following configuration to your appsettings.json:
{
"AttachmentSettings": {
"StorageType": "FTP",
"SharedLinkExpiryMinutes": 60,
"EXPIRY_IV_KEY": "EXAMBELKEY",
"MaxUploadSizeBytes": 52428800,
"MaxUploadSizeMB": 50,
"MaxFilesPerRequest": 10,
"AllowedFileExtensions": [".pdf", ".jpg", ".jpeg", ".png", ".docx", ".xlsx", ".zip"],
"FileSizeLimitsByExtension": {
".jpg": 10485760,
".jpeg": 10485760,
".png": 10485760,
".pdf": 20971520,
".docx": 20971520,
".xlsx": 20971520,
".zip": 104857600
},
"AWS": {
"Key": "your-aws-access-key",
"SecretKey": "your-aws-secret-key",
"BucketName": "your-bucket-name"
},
"FTP": {
"Server": "ftp://your-ftp-server.com",
"Username": "ftp-username",
"Password": "ftp-password"
},
"SmsSettings": {
"Provider": "sms-provider-name",
"BaseUrl": "https://sms-gateway.com/",
"SendPath": "api/send",
"UsernameParameter": "username",
"PasswordParameter": "password",
"SenderParameter": "Sender",
"TextParameter": "Text",
"NumberParameter": "number",
"Username": "your-sms-username",
"Password": "your-sms-password",
"Sender": "YourAppName",
"TimeoutSeconds": 30,
"UrlEncodeParameters": true,
"SuccessString": "",
"SuccessCriteria": {
"Type": "json",
"SuccessProperty": "Status",
"SuccessValue": "0"
},
"ErrorCriteria": {
"Type": "string",
"ErrorKeyword": "Error Code"
},
"OTPMessage": "Use the code {0} to log in."
}
}
}| Parameter | Type | Description |
|---|---|---|
StorageType | string | Storage provider to use: "AWS", "FTP", or "Local" |
SharedLinkExpiryMinutes | integer | Duration in minutes before shared links expire |
EXPIRY_IV_KEY | string | Base64 encoded initialization vector for encryption |
| Parameter | Type | Description |
|---|---|---|
MaxUploadSizeBytes | long | Maximum file size in bytes (default: 52428800 = 50 MB) |
MaxUploadSizeMB | integer | Maximum file size in megabytes for display purposes |
MaxFilesPerRequest | integer | Maximum number of files allowed per upload request |
AllowedFileExtensions | array | List of allowed file extensions (e.g., [".pdf", ".jpg"]). Leave empty to allow all extensions |
FileSizeLimitsByExtension | object | Dictionary of extension-specific size limits in bytes |
| Parameter | Type | Description |
|---|---|---|
Key | string | AWS access key ID |
SecretKey | string | AWS secret access key |
BucketName | string | S3 bucket name for file storage |
| Parameter | Type | Description |
|---|---|---|
Server | string | FTP server URL (include ftp:// or ftps://) |
Username | string | FTP account username |
Password | string | FTP account password |
| Parameter | Type | Description |
|---|---|---|
Provider | string | Name/identifier of the SMS provider |
BaseUrl | string | Base URL of the SMS gateway API |
SendPath | string | API endpoint path for sending SMS |
UsernameParameter | string | Parameter name for username in API request |
PasswordParameter | string | Parameter name for password in API request |
SenderParameter | string | Parameter name for sender ID in API request |
TextParameter | string | Parameter name for message text in API request |
NumberParameter | string | Parameter name for recipient number in API request |
Username | string | Your SMS gateway account username |
Password | string | Your SMS gateway account password |
Sender | string | Default sender name/ID for outgoing messages |
TimeoutSeconds | integer | Request timeout duration (default: 30) |
UrlEncodeParameters | boolean | Whether to URL encode parameters (default: true) |
SuccessString | string | Optional string to match for success (legacy) |
OTPMessage | string | Template for OTP messages. Use {0} for code placeholder |
| Parameter | Type | Description |
|---|---|---|
Type | string | Response format: "json" or "string" |
SuccessProperty | string | JSON property name to check for success (json type only) |
SuccessValue | string | Expected value indicating success |
| Parameter | Type | Description |
|---|---|---|
Type | string | Error detection format: "json" or "string" |
ErrorKeyword | string | Keyword/property indicating an error occurred |
{
"AttachmentSettings": {
"StorageType": "FTP",
"MaxUploadSizeBytes": 52428800,
"MaxUploadSizeMB": 50,
"MaxFilesPerRequest": 10
}
}{
"AttachmentSettings": {
"MaxUploadSizeBytes": 52428800,
"MaxFilesPerRequest": 5,
"AllowedFileExtensions": [".pdf", ".jpg", ".jpeg", ".png"],
"FileSizeLimitsByExtension": {
".jpg": 5242880,
".jpeg": 5242880,
".png": 5242880,
".pdf": 10485760
}
}
}This configuration:
{
"AttachmentSettings": {
"StorageType": "AWS",
"MaxUploadSizeBytes": 104857600,
"MaxUploadSizeMB": 100,
"AWS": {
"Key": "AKIAIOSFODNN7EXAMPLE",
"SecretKey": "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
"BucketName": "my-application-files"
}
}
}{
"AttachmentSettings": {
"StorageType": "FTP",
"MaxUploadSizeBytes": 52428800,
"FTP": {
"Server": "ftp://files.company.com",
"Username": "fileadmin",
"Password": "SecureP@ssw0rd"
}
}
}{
"AttachmentSettings": {
"SmsSettings": {
"SuccessCriteria": {
"Type": "json",
"SuccessProperty": "Status",
"SuccessValue": "0"
}
}
}
}Expected API response:
{
"Status": "0",
"Message": "SMS sent successfully"
}{
"AttachmentSettings": {
"SmsSettings": {
"SuccessCriteria": {
"Type": "string",
"SuccessValue": "SUCCESS"
},
"ErrorCriteria": {
"Type": "string",
"ErrorKeyword": "ERROR"
}
}
}
}Expected API response: "SUCCESS: Message delivered"
The library provides comprehensive file upload validation and management:
Upload validation: Files are automatically validated against configured size limits, allowed extensions, and extension-specific restrictions before upload
Multiple input formats: Supports both multipart form file uploads and Base64 encoded file content
Automatic format detection: The library can detect file formats from their binary signatures (magic numbers) for PDF, PNG, JPG, GIF, ZIP, BMP, and DOCX files
Size calculation: Automatically calculates file sizes for both FormFile and Base64Content inputs
Detailed error messages: Provides user-friendly error messages with actual file sizes in human-readable format (KB, MB, GB)
Batch validation: Validates multiple files in a single request, checking both individual file sizes and total upload size
The CojectFile class provides automatic validation with the following checks:
Upload a file: Files are automatically routed to AWS S3, FTP, or local storage based on configuration
Download a file: Retrieve files from the configured storage provider
Generate shared link: Create temporary links with automatic expiry based on SharedLinkExpiryMinutes
Delete a file: Remove files from the configured storage backend
Send OTP: The library uses the OTPMessage template to format one-time passwords
Send notifications: Send SMS messages through the configured provider
Custom parameters: The library maps your provider's parameter names using the configuration settings
Response validation: Automatically validates success/failure based on SuccessCriteria and ErrorCriteria
Send emails: SMTP integration with attachment support
Generate signatures: Professional email signature generation
HTML/Plain text: Support for both formats with template support
Encrypt data: Uses the configured EXPIRY_IV_KEY for secure encryption
Generate tokens: JWT token generation with configurable expiry
Shared links: Time-based security for temporary file access
File upload security: Prevents malicious uploads through extension and size restrictions
The library returns standardized error codes for different validation scenarios:
| Error Code | Description |
|---|---|
CojectFileHandler-01 | No files were provided for upload |
CojectFileHandler-02 | Exceeded maximum files per request limit |
CojectFileHandler-03 | File validation failed (size, extension, or format issues) |
CojectFileHandler-04 | Total upload size exceeds maximum allowed size |
File size exceeds limit:
{
"Messages": {
"CODE": "CojectFileHandler-03",
"MESSAGE": "Validation failed for 'document.pdf': File 'document.pdf' size (75.5 MB) exceeds maximum allowed size of 50 MB"
}
}Invalid file extension:
{
"Messages": {
"CODE": "CojectFileHandler-03",
"MESSAGE": "Validation failed for 'script.exe': File extension '.exe' is not allowed. Allowed extensions: .pdf, .jpg, .jpeg, .png, .docx"
}
}Too many files:
{
"Messages": {
"CODE": "CojectFileHandler-02",
"MESSAGE": "Maximum 10 files allowed per request. You provided 15 files."
}
}Extension-specific limit exceeded:
{
"Messages": {
"CODE": "CojectFileHandler-03",
"MESSAGE": "Validation failed for 'photo.jpg': File 'photo.jpg' size (12 MB) exceeds maximum allowed size for .jpg files (10 MB)"
}
}| File Type | Recommended Limit | Configuration Example |
|---|---|---|
| Images (JPG, PNG) | 5-10 MB | 10485760 bytes |
| Documents (PDF, DOCX) | 10-20 MB | 20971520 bytes |
| Spreadsheets (XLSX) | 10-20 MB | 20971520 bytes |
| Archives (ZIP, RAR) | 50-100 MB | 104857600 bytes |
| Videos | 100-500 MB | 524288000 bytes |
| General Files | 50 MB | 52428800 bytes |
CojectCore.Helper/
├── API/
│ └── APIHelper.cs
├── EmailManager/
│ ├── Entity/
│ ├── Interface/
│ └── Service/
├── FileSignatures/
│ ├── Abstract/
│ ├── Formats/
│ ├── Interface/
│ └── Service/
├── FilesManager/
│ ├── Entity/
│ │ └── CojectFile.cs (with validation)
│ ├── Interface/
│ │ └── ICojectFileControllerHelper.cs
│ └── Service/
│ ├── CojectFileControllerHelper.cs (with validation)
│ ├── CojectFileManager.cs
│ ├── CojectFileManagerAWS.cs
│ ├── CojectFileManagerFTP.cs
│ └── CojectFileManagerHelper.cs
├── BarcodeHelper.cs
├── DateHelper.cs
├── EncryptionHelper.cs
├── FileHelper.cs
├── ImageHelper.cs
├── JsonHelper.cs
├── MapDataHelper.cs
├── SmsHelper.cs
└── StringHelper.cs
This package includes the following key dependencies:
EXPIRY_IV_KEY for enhanced securitySharedLinkExpiryMinutes based on your security requirementsAllowedFileExtensions to prevent malicious file uploadsMaxUploadSizeBytes based on your application needs and server capacityFileSizeLimitsByExtensionMaxFilesPerRequest to prevent abuse and server overloadAllowedFileExtensions for securityUrlEncodeParameters if your provider requires encoded valuesTimeoutSeconds based on provider response timesOTPMessage to match your application's branding"Request size exceeds maximum allowed size"
MaxUploadSizeBytes in appsettings.jsonMaxRequestBodySize matches configurationFormOptions.MultipartBodyLengthLimit is set correctly in Program.cs"File extension not allowed"
AllowedFileExtensions array"File size exceeds maximum for extension"
FileSizeLimitsByExtension settings"Validation failed: Base64Content is not valid"
"Total upload size exceeds limit"
MaxUploadSizeBytesAWS S3 Connection Fails
Key and SecretKey are correctFTP Connection Fails
Messages Not Sending
BaseUrl and SendPath are correctSuccess/Error Not Detected
SuccessCriteria.Type to match response (json/string)Links Expire Too Quickly
SharedLinkExpiryMinutes valueEncryption Errors
EXPIRY_IV_KEY is valid Base64 string (16, 24, or 32 bytes when decoded)Settings Not Loading
Validation Not Working
CojectFileControllerHelper is properly injectedValidateFileUpload() is called before uploadThis package follows Semantic Versioning (SemVer). Current version: 1.0.36
For issues, feature requests, or contributions, please contact the development team at Akwad Arabia.
Copyright © Akwad Al-Arabia 2024. All rights reserved.
See LICENSE.txt for detailed license information.
Developed and maintained by Akwad Arabia
Part of the Coject Core ecosystem