Skip to content

Commit 341ea0e

Browse files
committed
integrate minor v8.4 docs
1 parent b5bb240 commit 341ea0e

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

MyApp/_pages/http-utils.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,23 @@ The following Core APIs also have extension methods on `HttpClient` which existi
125125
- `SendStreamToUrl()`
126126
- `SendStreamToUrlAsync()`
127127

128+
## HTTP Client Factory HTTP Utils
129+
130+
ServiceStack registers a named `IHttpClientFactory` that's configured with the same defaults as the built-in [HttpUtils](/http-utils) including using Default Credentials and support for Brotli, Deflate and GZip compression.
131+
132+
You can access this via `IHttpClientFactory.HttpUtilsClient()` extension method, e.g:
133+
134+
```csharp
135+
public class MyServices(IHttpClientFactory clientFactory) : Service
136+
{
137+
public async Task<object> Any(MyRequest request)
138+
{
139+
using HttpClient client = clientFactory.HttpUtilsClient();
140+
//...
141+
}
142+
}
143+
```
144+
128145
### Url Extensions
129146

130147
You can make use of the accompanying String Extensions to programmatically construct a url as seen in this Twitter API example:

MyApp/_pages/locode/files-overview.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,33 @@ let api = await client.apiForm(new MultipartRequest(), formData)
472472

473473
Where `apiForm` can be used to submit `FormData` requests for normal API Requests, or `apiFormVoid` for `IReturnVoid` API requests.
474474

475+
## API Keys protected managed File Uploads
476+
477+
Managed file uploads can also be protected with [Identity Auth API Keys](/auth/apikeys) by setting `requireApiKey:`, e.g:
478+
479+
```csharp
480+
var fileFs = new FileSystemVirtualFiles(context.HostingEnvironment.ContentRootPath);
481+
services.AddPlugin(new FilesUploadFeature(
482+
new UploadLocation("pub",
483+
fileFs,
484+
readAccessRole: RoleNames.AllowAnon,
485+
requireApiKey: new(),
486+
maxFileBytes: 10 * 1024 * 1024,
487+
resolvePath:ctx => "pub".CombineWith(ctx.Request.GetApiKey().Key, ctx.FileName)),
488+
new UploadLocation("secure",
489+
fileFs,
490+
requireApiKey: new("manager"),
491+
maxFileBytes: 10 * 1024 * 1024,
492+
resolvePath:ctx => "secure".CombineWith(ctx.Request.GetApiKey().Key, ctx.FileName))
493+
));
494+
```
495+
496+
This configuration shows a **pub** upload location allowing for anonymous reads but all writes requiring an API Key.
497+
498+
The **secure** upload location requires an API key with a **manager** [Scope](/auth/apikeys#scopes) which is required for both read and write access.
499+
500+
In both cases the upload locations will store the files in a sub-directory named after API Key used to upload it.
501+
475502
## Substitutable Virtual File Providers
476503

477504
We've also created the [File Blazor Demo](https://github.com/NetCoreApps/FileBlazor) to further demonstrate the versatility of the
@@ -555,9 +582,7 @@ private static void ValidateUpload(IRequest request, IHttpFile file)
555582

556583
### Memory Virtual File Sources
557584

558-
ServiceStack AppHost's are configured with an empty Memory VFS which can be used to transiently prepopulate App files
559-
from external sources on Startup or maintain temporary working files with the same lifetime of the App without needing
560-
to persist to disk.
585+
ServiceStack AppHost's are configured with an empty Memory VFS which can be used to transiently prepopulate App files from external sources on Startup or maintain temporary working files with the same lifetime of the App without needing to persist to disk.
561586

562587
They're also a great solution for Integration Testing managed file access without creating any persistent artifacts as done in
563588
[AutoQueryCrudTests.References.cs](https://github.com/ServiceStack/ServiceStack/blob/main/ServiceStack/tests/ServiceStack.WebHost.Endpoints.Tests/AutoQueryCrudTests.References.cs)

0 commit comments

Comments
 (0)