Skip to content

Commit 68742be

Browse files
committed
Add file upload docs
1 parent cd4c434 commit 68742be

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

docs/usage.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,31 @@ public async IAsyncEnumerable<SearchResponse> SearchStream(
380380

381381
The main limitation of this function is that it expects each JSON object to be returned as a single line. It is unable to parse the response by combining multiple lines into a JSON string.
382382

383+
### Uploading files
384+
385+
To add a file to the request you can use the `RestRequest` function called `AddFile`. The main function accepts the `FileParameter` argument:
386+
387+
```csharp
388+
request.AddFile(fileParameter);
389+
```
390+
391+
You can instantiate the file parameter using `FileParameter.Create` that accepts a bytes array, or `FileParameter.FromFile`, which will load the file from disk.
392+
393+
There are also extension functions that wrap the creation of `FileParameter` inside:
394+
395+
```csharp
396+
// Adds a file from disk
397+
AddFile(parameterName, filePath, contentType);
398+
399+
// Adds an array of bytes
400+
AddFile(parameterName, bytes, fileName, contentType);
401+
402+
// Adds a stream returned by the getFile function
403+
AddFile(parameterName, getFile, fileName, contentType);
404+
```
405+
406+
Remember that `AddFile` will set all the necessary headers, so please don't try to set content headers manually.
407+
383408
### Downloading binary data
384409

385410
There are two functions that allow you to download binary data from the remote API.

0 commit comments

Comments
 (0)