Skip to content
Written with Claude
IMPORTANT

As you may notice, this page and pretty much the entire website were obviously created with the help of AI. I wonder how you could tell? Was it a big "Written With Claude" badge on every page? I moved it to the top now (with the help of AI of course) to make it even more obvious. There are a few blogposts that were written by me manually, the old-fashioned way, I hope there will be more in the future, and those have a similar "Human Written" badge. This project (not the website), on the other hand, is a very, very different story. It took me more than two years of painstaking and unpaid work in my own free time. A story that, hopefully, I will tell someday. But meanwhile, what would you like me to do? To create a complex documentation website with a bunch of highly technical articles with the help of AI and fake it, to give you an illusion that I also did that manually? Like the half of itnernet is doing at this point? How does that makes any sense? Is that even fair to you? Or maybe to create this website manually, the old-fashioned way, just for you? While working a paid job for a salary, most of you wouldn't even get up in the morning. Would you like me to sing you a song while we're at it? For your personal entertainment? Seriously, get a grip. Do you find this information less valuable because of the way this website was created? I give my best to fix it to keep the information as accurate as possible, and I think it is very accurate at this point. If you find some mistakes, inaccurancies or problems, there is a comment section at the bottom of every page, which I also made with the help of the AI. And I woould very much appreciate if you leave your feedback there. Look, I'm just a guy who likes SQL, that's all. If you don't approve of how this website was constructed and the use of AI tools, I suggest closing this page and never wever coming back. And good riddance. And I would ban your access if I could know how. Thank you for your attention to this matter.

Upload Options

File upload configuration for handling uploads via PostgreSQL Large Objects, file system, CSV, and Excel handlers.

Overview

json
{
  "NpgsqlRest": {
    "UploadOptions": {
      "Enabled": false,
      "LogUploadEvent": true,
      "LogUploadParameters": false,
      "DefaultUploadHandler": "large_object",
      "UseDefaultUploadMetadataParameter": false,
      "DefaultUploadMetadataParameterName": "_upload_metadata",
      "UseDefaultUploadMetadataContextKey": false,
      "DefaultUploadMetadataContextKey": "request.upload_metadata",
      "UploadHandlers": {
        "StopAfterFirstSuccess": false,
        "IncludedMimeTypePatterns": null,
        "ExcludedMimeTypePatterns": null,
        "BufferSize": 8192,
        "TextTestBufferSize": 4096,
        "TextNonPrintableThreshold": 5,
        "AllowedImageTypes": "jpeg, png, gif, bmp, tiff, webp",
        "LargeObjectEnabled": true,
        "LargeObjectKey": "large_object",
        "LargeObjectCheckText": false,
        "LargeObjectCheckImage": false,
        "FileSystemEnabled": true,
        "FileSystemKey": "file_system",
        "FileSystemPath": "/tmp/uploads",
        "FileSystemUseUniqueFileName": true,
        "FileSystemCreatePathIfNotExists": true,
        "FileSystemCheckText": false,
        "FileSystemCheckImage": false,
        "CsvUploadEnabled": true,
        "CsvUploadKey": "csv",
        "CsvUploadCheckFileStatus": true,
        "CsvUploadDelimiterChars": ",",
        "CsvUploadHasFieldsEnclosedInQuotes": true,
        "CsvUploadSetWhiteSpaceToNull": true,
        "CsvUploadRowCommand": "call process_csv_row($1,$2,$3,$4)",
        "ExcelUploadEnabled": true,
        "ExcelKey": "excel",
        "ExcelSheetName": null,
        "ExcelAllSheets": false,
        "ExcelTimeFormat": "HH:mm:ss",
        "ExcelDateFormat": "yyyy-MM-dd",
        "ExcelDateTimeFormat": "yyyy-MM-dd HH:mm:ss",
        "ExcelRowDataAsJson": false,
        "ExcelUploadRowCommand": "call process_excel_row($1,$2,$3,$4)"
      }
    }
  }
}

General Settings

SettingTypeDefaultDescription
EnabledboolfalseEnable file upload handling.
LogUploadEventbooltrueLog upload events.
LogUploadParametersboolfalseLog upload parameters (file names, sizes, etc.).
DefaultUploadHandlerstring"large_object"Default handler when not specified.
UseDefaultUploadMetadataParameterboolfalsePass upload metadata via parameter.
DefaultUploadMetadataParameterNamestring"_upload_metadata"Parameter name for upload metadata JSON.
UseDefaultUploadMetadataContextKeyboolfalsePass upload metadata via context key.
DefaultUploadMetadataContextKeystring"request.upload_metadata"Context key for upload metadata JSON.

Upload Handlers Common Settings

Settings that apply to all upload handlers.

SettingTypeDefaultDescription
StopAfterFirstSuccessboolfalseStop processing after first successful handler.
IncludedMimeTypePatternsstringnullCSV of MIME type patterns to include. null to allow all.
ExcludedMimeTypePatternsstringnullCSV of MIME type patterns to exclude. null to exclude none.
BufferSizeint8192Buffer size in bytes for file_system and large_object handlers (8 KB).
TextTestBufferSizeint4096Buffer sample size for testing textual content (4 KB).
TextNonPrintableThresholdint5Maximum non-printable characters allowed in text buffer.
AllowedImageTypesstring"jpeg, png, gif, bmp, tiff, webp"Comma-separated list of allowed image types.

Large Object Handler

Uploads files using PostgreSQL Large Objects API.

json
{
  "NpgsqlRest": {
    "UploadOptions": {
      "UploadHandlers": {
        "LargeObjectEnabled": true,
        "LargeObjectKey": "large_object",
        "LargeObjectCheckText": false,
        "LargeObjectCheckImage": false
      }
    }
  }
}
SettingTypeDefaultDescription
LargeObjectEnabledbooltrueEnable Large Object upload handler.
LargeObjectKeystring"large_object"Handler key name.
LargeObjectCheckTextboolfalseValidate uploaded content is text.
LargeObjectCheckImageboolfalseValidate uploaded content is an allowed image type.

File System Handler

Uploads files to the server file system.

json
{
  "NpgsqlRest": {
    "UploadOptions": {
      "UploadHandlers": {
        "FileSystemEnabled": true,
        "FileSystemKey": "file_system",
        "FileSystemPath": "/tmp/uploads",
        "FileSystemUseUniqueFileName": true,
        "FileSystemCreatePathIfNotExists": true,
        "FileSystemCheckText": false,
        "FileSystemCheckImage": false
      }
    }
  }
}
SettingTypeDefaultDescription
FileSystemEnabledbooltrueEnable file system upload handler.
FileSystemKeystring"file_system"Handler key name.
FileSystemPathstring"/tmp/uploads"Directory path for uploaded files.
FileSystemUseUniqueFileNamebooltrueGenerate unique file names to prevent overwrites.
FileSystemCreatePathIfNotExistsbooltrueCreate upload directory if it doesn't exist.
FileSystemCheckTextboolfalseValidate uploaded content is text.
FileSystemCheckImageboolfalseValidate uploaded content is an allowed image type.

CSV Upload Handler

Uploads CSV files and processes rows via a PostgreSQL command.

json
{
  "NpgsqlRest": {
    "UploadOptions": {
      "UploadHandlers": {
        "CsvUploadEnabled": true,
        "CsvUploadKey": "csv",
        "CsvUploadCheckFileStatus": true,
        "CsvUploadDelimiterChars": ",",
        "CsvUploadHasFieldsEnclosedInQuotes": true,
        "CsvUploadSetWhiteSpaceToNull": true,
        "CsvUploadRowCommand": "call process_csv_row($1,$2,$3,$4)"
      }
    }
  }
}
SettingTypeDefaultDescription
CsvUploadEnabledbooltrueEnable CSV upload handler.
CsvUploadKeystring"csv"Handler key name.
CsvUploadCheckFileStatusbooltrueCheck file status before processing.
CsvUploadDelimiterCharsstring","CSV field delimiter character(s).
CsvUploadHasFieldsEnclosedInQuotesbooltrueFields may be enclosed in quotes.
CsvUploadSetWhiteSpaceToNullbooltrueConvert whitespace-only values to NULL.
CsvUploadRowCommandstring"call process_csv_row($1,$2,$3,$4)"PostgreSQL command to process each row.

CSV Row Command Parameters

ParameterTypeDescription
$1intRow index (1-based).
$2text[]Parsed values as text array.
$3textResult of previous row command.
$4jsonUpload metadata JSON.

Excel Upload Handler

Uploads Excel files and processes rows via a PostgreSQL command.

json
{
  "NpgsqlRest": {
    "UploadOptions": {
      "UploadHandlers": {
        "ExcelUploadEnabled": true,
        "ExcelKey": "excel",
        "ExcelSheetName": null,
        "ExcelAllSheets": false,
        "ExcelTimeFormat": "HH:mm:ss",
        "ExcelDateFormat": "yyyy-MM-dd",
        "ExcelDateTimeFormat": "yyyy-MM-dd HH:mm:ss",
        "ExcelRowDataAsJson": false,
        "ExcelUploadRowCommand": "call process_excel_row($1,$2,$3,$4)"
      }
    }
  }
}
SettingTypeDefaultDescription
ExcelUploadEnabledbooltrueEnable Excel upload handler.
ExcelKeystring"excel"Handler key name.
ExcelSheetNamestringnullSheet name to process. null for first available sheet.
ExcelAllSheetsboolfalseProcess all sheets in the workbook.
ExcelTimeFormatstring"HH:mm:ss"Format for time values.
ExcelDateFormatstring"yyyy-MM-dd"Format for date values.
ExcelDateTimeFormatstring"yyyy-MM-dd HH:mm:ss"Format for datetime values.
ExcelRowDataAsJsonboolfalsePass row data as JSON instead of text array.
ExcelUploadRowCommandstring"call process_excel_row($1,$2,$3,$4)"PostgreSQL command to process each row.

Excel Row Command Parameters

ParameterTypeDescription
$1intRow index (1-based).
$2text[] or jsonParsed values as text array (or JSON if ExcelRowDataAsJson is true).
$3textResult of previous row command.
$4jsonUpload metadata JSON.

Complete Example

Production configuration with file system and CSV uploads:

json
{
  "NpgsqlRest": {
    "UploadOptions": {
      "Enabled": true,
      "LogUploadEvent": true,
      "LogUploadParameters": false,
      "DefaultUploadHandler": "file_system",
      "UseDefaultUploadMetadataParameter": true,
      "DefaultUploadMetadataParameterName": "_upload_metadata",
      "UploadHandlers": {
        "StopAfterFirstSuccess": true,
        "IncludedMimeTypePatterns": "image/*,text/*,application/pdf",
        "ExcludedMimeTypePatterns": null,
        "BufferSize": 16384,
        "LargeObjectEnabled": false,
        "FileSystemEnabled": true,
        "FileSystemPath": "/var/uploads",
        "FileSystemUseUniqueFileName": true,
        "FileSystemCreatePathIfNotExists": true,
        "FileSystemCheckImage": true,
        "CsvUploadEnabled": true,
        "CsvUploadDelimiterChars": ",",
        "CsvUploadRowCommand": "call import_csv_row($1,$2,$3,$4)",
        "ExcelUploadEnabled": true,
        "ExcelUploadRowCommand": "call import_excel_row($1,$2,$3,$4)"
      }
    }
  }
}

Blog Posts

Next Steps

Comments

Released under the MIT License.