Search Results for

Show / Hide Table of Contents

# Class TusStorage

Filesystem-backed storage for tus 1.0.0 sessions. Each session is a directory under {TempDirectory}/tus-sessions/{id}/ containing an appendable `data.bin` and a `meta.json` sidecar. Session ids are random hex strings; the id is validated to contain only [a-z0-9-] before being joined with the temp path to prevent traversal.

##### Inheritance

object
TusStorage

##### 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 TusStorage

### Constructors

#### TusStorage(IOptions<CoreUploadOptions>, IWebHostEnvironment)

##### Declaration

    public TusStorage(IOptions<CoreUploadOptions> options, IWebHostEnvironment env)

##### Parameters

Type | Name | Description
--- | --- | ---
IOptions<CoreUploadOptions> | options |
IWebHostEnvironment | env |

### Methods

#### Abort(string)

Deletes the session directory and all contents.

##### Declaration

    public void Abort(string id)

##### Parameters

Type | Name | Description
--- | --- | ---
string | id |

#### AppendAsync(string, long, Stream, CancellationToken)

Appends `body` to the session starting at `expectedOffset`. Returns the new offset.

##### Declaration

    public Task<long> AppendAsync(string id, long expectedOffset, Stream body, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
string | id |
long | expectedOffset |
Stream | body |
CancellationToken | ct |

##### Returns

Type | Description
--- | ---
Task<long> |

##### Exceptions

Type | Condition
--- | ---
InvalidOperationException | Session missing or offset mismatch.

#### AppendWithChecksumAsync(string, long, Stream, string, byte[], CancellationToken)

Appends `body` at `expectedOffset` while computing a digest of the received bytes (tus checksum extension). On digest mismatch the file is truncated back to `expectedOffset` — no corrupt bytes are committed — and TusStorage.TusChecksumMismatchException is thrown so the endpoint can answer 460.

##### Declaration

    public Task<long> AppendWithChecksumAsync(string id, long expectedOffset, Stream body, string algorithm, byte[] expectedDigest, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
string | id | Session identifier.
long | expectedOffset | Offset the client believes the server is at.
Stream | body | Request body carrying the chunk bytes.
string | algorithm | "sha1" or "sha256".
byte[] | expectedDigest | Digest of the chunk as sent by the client.
CancellationToken | ct | Cancellation token.

##### Returns

Type | Description
--- | ---
Task<long> |

##### Exceptions

Type | Condition
--- | ---
InvalidOperationException | Session missing or offset mismatch.
TusStorage.TusChecksumMismatchException | Received bytes do not match the digest.

#### CreateSessionAsync(long, string?, string?, CancellationToken)

Creates a new tus session and returns its identifier.

##### Declaration

    public Task<string> CreateSessionAsync(long uploadLength, string? fileName, string? contentType, CancellationToken ct = default)

##### Parameters

Type | Name | Description
--- | --- | ---
long | uploadLength |
string | fileName |
string | contentType |
CancellationToken | ct |

##### Returns

Type | Description
--- | ---
Task<string> |

#### GetMetaAsync(string, CancellationToken)

Gets metadata for a session, or null if not found.

##### Declaration

    public Task<TusStorage.TusMetadata?> GetMetaAsync(string id, CancellationToken ct = default)

##### Parameters

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

##### Returns

Type | Description
--- | ---
Task<TusStorage.TusMetadata> |

#### GetOffset(string)

Returns the current uploaded-bytes offset, or -1 if the session does not exist.

##### Declaration

    public long GetOffset(string id)

##### Parameters

Type | Name | Description
--- | --- | ---
string | id |

##### Returns

Type | Description
--- | ---
long |

#### OpenForRead(string)

Opens the accumulated upload as a readable stream for hand-off to the upload pipeline. Caller disposes. Session directory is not deleted — call Abort(string) after.

##### Declaration

    public FileStream OpenForRead(string id)

##### Parameters

Type | Name | Description
--- | --- | ---
string | id |

##### Returns

Type | Description
--- | ---
FileStream |