Skip to main content

Commands: UploadAsync

Syntax

#Commands: UploadAsync

UploadAsync is used to insert a new file or update the content of an existing one in a file system.

Task UploadAsync(string filename, Stream source, RavenJObject metadata = null, Etag etag = null);
Parameters
filenamestringThe name of the uploaded file (full path)
sourceStreamThe file content
metadataRavenJObjectThe file metadata (default: null)
etagEtagThe current file etag used for concurrency checks (null skips check)
Return Value
TaskA task that represents the asynchronous upload operation
Task UploadAsync(string filename, Action<Stream> source, Action prepareStream, long size, RavenJObject metadata = null, Etag etag = null);
Parameters
filenamestringThe name of the uploaded file (full path)
sourceAction<Stream>The action which writes file content to the network stream
prepareStreamActionThe action executed before the content is being written (null means no action to perform)
sizelongThe file size. It is sent in RavenFS-Size header to validate the number of bytes received on the server side. If there is a mismatch between the size reported in the header and the number of the bytes read on the server side, then BadRequestException is thrown
metadataRavenJObjectThe file metadata (default: null)
etagEtagThe current file etag used for concurrency checks (null skips check)
Return Value
TaskA task that represents the asynchronous upload operation

Example I

using (var file = File.OpenRead(@"C:\intro.avi"))
{
await store
.AsyncFilesCommands
.UploadAsync(
"/movies/intro.avi",
file,
new RavenJObject
{
{
"AllowRead", "Everyone"
}
}
);
}

Example II

await store
.AsyncFilesCommands
.UploadAsync(
"two-bytes-file.bin",
s =>
{
s.WriteByte(1);
s.WriteByte(2);
},
null,
2,
new RavenJObject
{
{
"AllowRead", "Everyone"
}
}
);