Show / Hide Table of Contents

Class Upload

Upload class for Editor. This class provides the ability to easily specify file upload information, specifically how the file should be recorded on the server (database and file system).

An instance of this class is attached to a field using the 'Field.upload()' method. When Editor detects a file upload for that file the information provided for this instance is executed.

The configuration is primarily driven through the 'db' and 'action' methods

Inheritance
System.Object
Upload
Namespace: DataTables
Assembly: DataTables-Editor-Server.dll
Syntax
public class Upload : object

Constructors

| Improve this Doc View Source

Upload()

Upload constructor

Declaration
public Upload()
| Improve this Doc View Source

Upload(Func<Microsoft.AspNetCore.Http.IFormFile, Object, Object>)

Upload constructor with a function action

Declaration
public Upload(Func<Microsoft.AspNetCore.Http.IFormFile, dynamic, dynamic> action)
Parameters
Type Name Description
Func<Microsoft.AspNetCore.Http.IFormFile, System.Object, System.Object> action

Callback function that is executed when a file is uploaded.

| Improve this Doc View Source

Upload(String)

Upload constructor with a path action

Declaration
public Upload(string action)
Parameters
Type Name Description
System.String action

Location for where to store the file. This should be an absolute path on your system.

Methods

| Improve this Doc View Source

Action(Func<Microsoft.AspNetCore.Http.IFormFile, Object, Object>)

Set the action to take when a file is uploaded. As a function the callback is given the responsiblity of what to do with the uploaded file. That will typically involve writing it to the file system so it can be used later.

Declaration
public Upload Action(Func<Microsoft.AspNetCore.Http.IFormFile, dynamic, dynamic> action)
Parameters
Type Name Description
Func<Microsoft.AspNetCore.Http.IFormFile, System.Object, System.Object> action

Callback

Returns
Type Description
Upload

Self for chaining

| Improve this Doc View Source

Action(String)

Set the action to take when a file is uploaded. As a string the value given is the full system path to where the uploaded file is written to. The value given can include three "macros" which are replaced by the script dependent on the uploaded file:

  • 'EXTN' - the file extension (with the dot)
  • 'NAME' - the uploaded file's name (including the extension)
  • 'ID' - Database primary key value if the 'Db()' method is used
Declaration
public Upload Action(string action)
Parameters
Type Name Description
System.String action

Full system path for where the file should be stored

Returns
Type Description
Upload

Self for chaining

| Improve this Doc View Source

AllowedExtensions(IEnumerable<String>, String)

A list of valid file extensions that can be uploaded. This is for simple validation that the file is of the expected type. The check is case-insensitive. If no extensions are given, no validation is performed on the file extension.

Declaration
public Upload AllowedExtensions(IEnumerable<string> extns, string error = "This file type cannot be uploaded")
Parameters
Type Name Description
IEnumerable<System.String> extns

List of extensions to test against.

System.String error

Error message for if the file is not valid.

Returns
Type Description
Upload

Self for chaining

| Improve this Doc View Source

Db(String, String, Dictionary<String, Object>, Action<Dictionary<String, Object>>)

Database configuration method. When used, this method will tell Editor what information you want to be wirtten to a database on file upload, should you wish to store relational information about your files on the database (this is generally recommended).

Declaration
public Upload Db(string table, string pkey, Dictionary<string, object> fields, Action<Dictionary<string, object>> format = null)
Parameters
Type Name Description
System.String table

Name of the table where the file information should be stored

System.String pkey

Primary key column name. This is required so each row can be uniquely identified.

Dictionary<System.String, System.Object> fields

A list of the fields to be wirtten to on upload. The dictonary keys are used as the database column names and the values can be defined by the 'DbType' enum of this class. The value can also be a string, which will be written directly to the database, or a function which will be executed and the returned value written to the database.

Action<Dictionary<System.String, System.Object>> format
Returns
Type Description
Upload

Self for chanining

| Improve this Doc View Source

DbClean(Func<List<Dictionary<String, Object>>, Boolean>)

Set a callback function that is used to remove files which no longer have a reference in a source table.

Declaration
public Upload DbClean(Func<List<Dictionary<string, object>>, bool> callback)
Parameters
Type Name Description
Func<List<Dictionary<System.String, System.Object>>, System.Boolean> callback

Function that will be executed on clean. It is given a List of information from the database about the orphaned rows, and can return true to indicate that the rows should be removed from the database. Any other return value (including none) will result in the records being retained.

Returns
Type Description
Upload

Self for chaining

| Improve this Doc View Source

DbClean(String, Func<List<Dictionary<String, Object>>, Boolean>)

Set a callback function that is used to remove files which no longer have a reference in a source table.

Declaration
public Upload DbClean(string tableField, Func<List<Dictionary<string, object>>, bool> callback)
Parameters
Type Name Description
System.String tableField

The table and field ("table.field" format) that should be used to check and see if a file reference is being used.

Func<List<Dictionary<System.String, System.Object>>, System.Boolean> callback

Function that will be executed on clean. It is given a List of information from the database about the orphaned rows, and can return true to indicate that the rows should be removed from the database. Any other return value (including none) will result in the records being retained.

Returns
Type Description
Upload

Self for chaining

| Improve this Doc View Source

Validator(Func<Microsoft.AspNetCore.Http.IFormFile, String>)

Add a validation method to check file uploads. Multiple validators can be added by calling this method multiple times. They will be executed in sequence when a file has been uploaded.

Declaration
public Upload Validator(Func<Microsoft.AspNetCore.Http.IFormFile, string> fn)
Parameters
Type Name Description
Func<Microsoft.AspNetCore.Http.IFormFile, System.String> fn

Validation function. The function takes a single parameter, an HttpPostedFile, and a string is returned on error with the error message. If the validation does not fail, 'null' should be returned.

Returns
Type Description
Upload

Self for chaining

| Improve this Doc View Source

Where(Action<Query>)

Add one or more WHERE conditions to the data that is retrieved from the database when querying it for the list of available files in a table.

Declaration
public Upload Where(Action<Query> fn)
Parameters
Type Name Description
Action<Query> fn

Delegate to execute adding where conditions to the query

Returns
Type Description
Upload

Self for chaining

  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX