Search Results for

Show / Hide Table of Contents

# Class UploadService

Default implementation of IUploadService that validates files, stores them through the configured provider, and raises upload events.

##### Inheritance

object
UploadService

##### Implements

IUploadService

##### Inherited Members

object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()

###### Namespace: CoreUpload.Services

###### Assembly: CoreUpload.dll

##### Syntax

    public class UploadService : IUploadService

### Constructors

#### UploadService(IUploaderProvider, IUploadProgressService, IOptions<CoreUploadOptions>, IEnumerable<IUploadEventHandler>)

##### Declaration

    public UploadService(IUploaderProvider provider, IUploadProgressService progress, IOptions<CoreUploadOptions> options, IEnumerable<IUploadEventHandler> eventHandlers)

##### Parameters

Type | Name | Description
--- | --- | ---
IUploaderProvider | provider |
IUploadProgressService | progress |
IOptions<CoreUploadOptions> | options |
IEnumerable<IUploadEventHandler> | eventHandlers |

### Methods

#### CompleteChunkedUploadAsync(string, string, int, CancellationToken)

Assembles all saved chunks for an upload session, updates progress, and raises the uploaded event for the completed file.

##### Declaration

    public Task<UploadResult> CompleteChunkedUploadAsync(string uploadId, string fileName, int totalChunks, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
string | uploadId |
string | fileName |
int | totalChunks |
CancellationToken | ct |

##### Returns

Type | Description
--- | ---
Task<UploadResult> |

#### CopyFileAsync(Guid, string, CancellationToken)

Copies an uploaded file to another destination while preserving the original stored upload.

##### Declaration

    public Task CopyFileAsync(Guid fileGuid, string destinationPath, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
Guid | fileGuid |
string | destinationPath |
CancellationToken | ct |

##### Returns

Type | Description
--- | ---
Task |

#### DeleteFileAsync(Guid, CancellationToken)

Deletes a previously uploaded file and its associated metadata.

##### Declaration

    public Task DeleteFileAsync(Guid fileGuid, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
Guid | fileGuid |
CancellationToken | ct |

##### Returns

Type | Description
--- | ---
Task |

#### GetChunkStatusAsync(string, CancellationToken)

Gets the chunk indexes and stored sizes the server currently holds for an upload session. Returns null when the provider cannot enumerate chunks (custom providers without `GetSavedChunksAsync`).

##### Declaration

    public Task<IReadOnlyDictionary<int, long>?> GetChunkStatusAsync(string uploadId, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
string | uploadId |
CancellationToken | ct |

##### Returns

Type | Description
--- | ---
Task<IReadOnlyDictionary<int, long>> |

#### GetFileInfoAsync(Guid, CancellationToken)

Gets metadata for a previously uploaded file. Returns null when the file cannot be found.

##### Declaration

    public Task<UploadedFileInfo?> GetFileInfoAsync(Guid fileGuid, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
Guid | fileGuid |
CancellationToken | ct |

##### Returns

Type | Description
--- | ---
Task<UploadedFileInfo> |

#### MoveFileAsync(Guid, string, CancellationToken)

Moves an uploaded file to a permanent destination and removes the original temporary copy.

##### Declaration

    public Task MoveFileAsync(Guid fileGuid, string destinationPath, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
Guid | fileGuid |
string | destinationPath |
CancellationToken | ct |

##### Returns

Type | Description
--- | ---
Task |

#### OpenFileAsync(Guid, CancellationToken)

Opens a readable stream for a previously uploaded file. The caller is responsible for disposing the returned stream.

##### Declaration

    public Task<Stream> OpenFileAsync(Guid fileGuid, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
Guid | fileGuid |
CancellationToken | ct |

##### Returns

Type | Description
--- | ---
Task<Stream> |

#### UploadChunkAsync(string, int, int, string, long, Stream, CancellationToken)

Saves one chunk for the supplied upload session. Validation is performed on the first chunk before any data is persisted.

##### Declaration

    public Task<UploadResult> UploadChunkAsync(string uploadId, int chunkIndex, int totalChunks, string fileName, long totalFileSize, Stream chunkStream, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
string | uploadId |
int | chunkIndex |
int | totalChunks |
string | fileName |
long | totalFileSize |
Stream | chunkStream |
CancellationToken | ct |

##### Returns

Type | Description
--- | ---
Task<UploadResult> |

#### UploadFileAsync(Stream, string, long, string?, CancellationToken)

Validates a file, persists it through the configured provider, and raises validation and completion events.

##### Declaration

    public Task<UploadResult> UploadFileAsync(Stream fileStream, string fileName, long fileSize, string? contentType = null, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
Stream | fileStream |
string | fileName |
long | fileSize |
string | contentType |
CancellationToken | ct |

##### Returns

Type | Description
--- | ---
Task<UploadResult> |

#### ValidateFile(string, long, string?)

Validates a file against the configured size, extension, and MIME-type restrictions. Returns null when the file is valid; otherwise returns a human-readable error message.

##### Declaration

    public string? ValidateFile(string fileName, long fileSize, string? contentType = null)

##### Parameters

Type | Name | Description
--- | --- | ---
string | fileName |
long | fileSize |
string | contentType |

##### Returns

Type | Description
--- | ---
string |

### Implements

IUploadService