Commands: UploadAsync
UploadAsync is used to insert a new file or update the content of an existing one in a file system.
Syntax
Task UploadAsync(string filename, Stream source, RavenJObject metadata = null, Etag etag = null);
Parameters |
|
|
filename |
string |
The name of the uploaded file (full path) |
source |
Stream |
The file content |
metadata |
RavenJObject |
The file metadata (default: null ) |
etag |
Etag |
The current file etag used for concurrency checks (null skips check) |
Return Value |
|
Task |
A 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 |
|
|
filename |
string |
The name of the uploaded file (full path) |
source |
Action<Stream> |
The action which writes file content to the network stream |
prepareStream |
Action |
The action executed before the content is being written (null means no action to perform) |
size |
long |
The 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 |
metadata |
RavenJObject |
The file metadata (default: null ) |
etag |
Etag |
The current file etag used for concurrency checks (null skips check) |
Return Value |
|
Task |
A 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"
}
}
);