Class TusStorage
Filesystem-backed storage for tus 1.0.0 sessions. Each session is a directory
under {temp}/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.
Inherited Members
Namespace: AjaxUploader.Services
Assembly: AjaxUploader.dll
Syntax
public class TusStorage
Methods
Abort(string)
Deletes the session directory and all contents.
Declaration
public void Abort(string id)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id |
Append(string, long, Stream)
Appends body to the session starting at expectedOffset.
Returns the new offset.
Declaration
public long Append(string id, long expectedOffset, Stream body)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | |
| long | expectedOffset | |
| Stream | body |
Returns
| Type | Description |
|---|---|
| long |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Thrown when the session is missing or the offset doesn't match. |
AppendWithChecksum(string, long, Stream, string, byte[])
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 handler can answer 460.
Declaration
public long AppendWithChecksum(string id, long expectedOffset, Stream body, string algorithm, byte[] expectedDigest)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | The tus session identifier. |
| long | expectedOffset | The offset the client believes the session is at. |
| Stream | body | The PATCH request body stream. |
| string | algorithm | "sha1" or "sha256". |
| byte[] | expectedDigest | The decoded digest from the Upload-Checksum header. |
Returns
| Type | Description |
|---|---|
| long |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | Session missing or offset mismatch. |
| TusStorage.TusChecksumMismatchException | Received bytes do not match the digest. |
CreateSession(long, string, string)
Creates a new tus session and returns its identifier.
Declaration
public string CreateSession(long uploadLength, string fileName, string contentType)
Parameters
| Type | Name | Description |
|---|---|---|
| long | uploadLength | |
| string | fileName | |
| string | contentType |
Returns
| Type | Description |
|---|---|
| string |
GetMeta(string)
Declaration
public TusStorage.TusMetadata GetMeta(string id)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id |
Returns
| Type | Description |
|---|---|
| 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. File is not deleted - call Abort(string) after consumption.
Declaration
public FileStream OpenForRead(string id)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id |
Returns
| Type | Description |
|---|---|
| FileStream |