Cloud Storage

Publish documents to a storage service and serve them from it

Doconut can keep a document's rendered pages in a storage service instead of in the memory of the node that opened it. The work has two halves, as in Distributed Deployments: the publisher renders the document and writes its pages into the store, and a cloud handler reads them back and answers the viewer's page requests.

The cloud types live in the Doconut.Clouds namespace, in Doconut.Clouds.dll, which ships inside the Doconut.NET8 package. There is no separate package to install and no separate license: cloud storage comes with the viewer license. Search and annotations on a cloud document still need the Search and Annotation plugin licenses, exactly as they do on a local one.

Providers

Each store has a configuration class, a CloudLocation value, and a handler:

CloudLocationConfigurationHandlerPublish target
AzureAzureConfigAzureCloudHandleryes
AmazonS3AmazonConfigAmazonS3CloudHandleryes
GoogleCloudGoogleCloudConfigGoogleCloudHandleryes
DropBoxDropBoxConfigDropBoxCloudHandleryes
FTPFTPConfigFTPCloudHandleryes
RedisRedisConfigRedisCloudHandleryes
FileShareFileShareConfigFileShareCloudHandleryes (the default)
CDNCDNConfigCDNCloudHandlerno — read only
None———

Every published document is stored under its token: {token}/1.png, {token}/docInfo.txt, and so on. A CDN cannot be published into; publish into the store the CDN serves, and let CDNCloudHandler read from {DoconutCdnUrl}/{token}/.

The SDK's samples cover Azure, Amazon S3 and a file share. FTP and Redis have no sample; their configuration and handler are as listed here.

Provider settings

All configurations derive from CloudUploadConfig, which carries Location (the store's CloudLocation) and Token. Leave Token empty: the publisher stamps each document's token on its own copy of the configuration, so one instance can serve many documents at once. TokenPath is the token followed by /. ToJson() and LoadFromJson(Type, string) serialise a configuration and read it back.

ConfigurationProperties
AzureConfigDoconutAzureStorageConnectionString, DoconutAzureContainerName
AmazonConfigDoconutAwsS3Key, DoconutAwsS3Secret, DoconutAwsS3BucketName, DoconutAwsS3RegionEndpoint (a region name such as us-east-1)
GoogleCloudConfigDoconutGoogleServiceAuthJsonFile (path to the service-account JSON file), DoconutGoogleBucketName
DropBoxConfigDoconutDropBoxToken (an OAuth2 access token)
FTPConfigDoconutFtpHost, DoconutFtpUser, DoconutFtpPassword, DoconutFtpSecure (FTPS when true)
RedisConfigDoconutRedisConnectionString
CDNConfigDoconutCdnUrl (the base URL the pages are served from)
FileShareConfigRootPath, TempPath, ReadOnly, UsePerTokenSubfolders, ReadReadyPollMs — see Distributed Deployments

FileShareConfig.TempPath is also the publisher's local working folder when it publishes into any other store. Left empty, the publisher uses a DoconutDistributed folder in the system temp folder. ReadOnly = true makes the file-share handler skip every write and delete.

Create the container or bucket before the first publish: the SDK's Azure and Amazon S3 samples create theirs out of band, not through Doconut.

Register the store

Build each configuration once and register it, so the publisher and the handler read the same object:

csharp
using Doconut.Clouds;
using Doconut.Middleware;

builder.Services.AddDoconutDistributedAsyncPublish();

builder.Services.AddSingleton(new AzureConfig
{
    Location                            = CloudLocation.Azure,
    DoconutAzureStorageConnectionString = "<connection-string>",
    DoconutAzureContainerName           = "doconut-artifacts",
});

// The publisher's local working folder. RootPath stays empty: the pages go to the container.
builder.Services.AddSingleton(new FileShareConfig
{
    Location = CloudLocation.FileShare,
    TempPath = Path.Combine(builder.Environment.ContentRootPath, "App_Data", "Staging"),
});

For Amazon S3, register an AmazonConfig with Location = CloudLocation.AmazonS3 instead; the rest of the page does not change except for the handler's type argument and TargetLocation.

Serve from the store

UseDoconutCloud<THandler> mounts the handler for one store. Put it on the branch the viewer calls — /doconut, matching BasePath: 'doconut' — behind the ticket check from Distributed Deployments:

csharp
using Doconut.Clouds;
using Doconut.Clouds.Handlers;
using Doconut.Middleware;
using Doconut.Security;

var app = builder.Build();

app.UseDoconutResources();
app.Map("/doconut", branch =>
{
    branch.UseDoconutDistributedDocumentSecurity();
    branch.UseDoconutCloud<AzureCloudHandler>(options =>
    {
        options.CloudUploadConfig = app.Services.GetRequiredService<AzureConfig>();
        options.FunctionsConfig   = new FunctionsConfig { RotateFlip = true, Links = true };
    }, "/");
});

The second argument is the path prefix. With "/" (or an empty string) the handler answers every request that reaches it; with any other value it is mounted on that path. The default is "/doconut-cloud".

The handler connects to the store on the first request. If connecting fails, that request is answered 503 with Cloud storage unavailable.; the next request tries to connect again.

AddDoconutCloud and UseDoconutCloud()

When one store serves the whole application, register the options once and let the configuration's type pick the handler:

csharp
using Doconut.Clouds;

builder.Services.AddDoconutCloud(options =>
{
    options.CloudUploadConfig = new AmazonConfig
    {
        Location                   = CloudLocation.AmazonS3,
        DoconutAwsS3Key            = "<access-key>",
        DoconutAwsS3Secret         = "<secret-key>",
        DoconutAwsS3BucketName     = "doconut-artifacts",
        DoconutAwsS3RegionEndpoint = "us-east-1",
    };
});

Then call branch.UseDoconutCloud() where the read-side sample calls UseDoconutCloud<AzureCloudHandler>. AddDoconutCloud throws ArgumentException when CloudUploadConfig is not set, and UseDoconutCloud() throws InvalidOperationException for a configuration type it does not know.

Publish into the store

DistributedDocumentPublishOptions.TargetLocation and TargetConfig send the pages to the store instead of a file share. TargetConfig takes the same configuration the handler uses. With background publishing and FirstPagePriority = true, page 1 is uploaded first and the document opens while the rest is still uploading:

csharp
using Doconut.Clouds;
using Doconut.Distribution;

app.MapPost("/api/open", async (string fileName, AzureConfig azure, FileShareConfig staging,
    IDistributedPublishQueue publishQueue, CancellationToken ct) =>
{
    var path           = Path.Combine("files", Path.GetFileName(fileName));
    var publishOptions = new DistributedDocumentPublishOptions
    {
        TargetLocation    = CloudLocation.Azure,
        TargetConfig      = azure,
        FirstPagePriority = true,
        FunctionsConfig   = new FunctionsConfig { Links = true },
    };

    var token = await publishQueue.EnqueueAsync(path, staging, publishOptions: publishOptions, ct: ct);
    return Results.Text(token);
});

TargetLocation defaults to CloudLocation.FileShare. For any other store TargetConfig is required, and the publisher throws InvalidOperationException without it; CloudLocation.CDN throws NotSupportedException. The FileShareConfig passed to the publisher only gives the working folder here; its RootPath is needed only for a file share.

A page that has not been uploaded yet is answered HTTP 202 Accepted. Turn on retryOn409: true in the viewer so it asks again — see Pages that are not written yet. DistributedDocumentPublisher.PublishAsync works with a cloud target too; it returns when every page is uploaded.

CloudOptions

PropertyDefaultPurpose
CloudUploadConfignullThe store's configuration. The handler reads its settings from here
FunctionsConfigall offThe features the handler serves — see below
Password""The administrator password for the clear-cloud-config request. It is not a document password
LogErrorsfalseWrite handler errors to files in LogPath
LogPath""An existing folder for those files; one file per error

clear-cloud-config drops the handler's connection, so the next request connects again. Send it as a POST to the handler with ?clear-cloud-config and a JSON body { "password": "…" }; any other method is answered 405. While Password is empty, the request is always refused.

FunctionsConfig

FunctionsConfig turns features on for cloud documents. All flags default to false.

FlagEffect
SearchAnswers search requests. Also needs the Search plugin license; without it the answer is ERR
AnnotationSaves and loads annotations. Also needs the Annotation plugin license
RotateFlipAllows the rotate and flip actions
LinksServes the document's hyperlinks
WatermarkApplies the watermark text stored with the document
HideHonours pages marked as hidden in the store

It is read in two places. On DistributedDocumentPublishOptions.FunctionsConfig it decides what is written: Search writes the search index and Links writes the hyperlinks. A feature that is off when the document is published is not available for it later. On CloudOptions.FunctionsConfig it decides what the handler serves. A document.config file stored with a document — a FunctionsConfig written with ToJson() — takes the place of the handler's flags for that document; FunctionsConfig.LoadFromJson reads one back.

An unlicensed application is served with the evaluation watermark whatever these flags say.

Removing old documents

On a file share, AddDoconutDistributedRetention runs a background sweep that deletes token folders left idle — nothing written to them and no page served from them — for longer than Ttl:

csharp
using Doconut.Clouds;

builder.Services.AddDoconutDistributedRetention(options =>
{
    options.RootPath = @"\\fileserver\doconut";   // the FileShareConfig.RootPath
    options.Ttl      = TimeSpan.FromHours(24);
});
ArtifactRetentionOptionsDefaultPurpose
RootPath""The file-share root holding the token folders. Required
TtlTimeSpan.ZeroHow long a folder may sit idle. Zero turns retention off
SweepInterval10 minutesHow often the sweep runs

The sweep cleans file shares only. In a container or bucket, expire documents with the store's own lifecycle rules, or delete the {token}/ prefix when a document is no longer needed. With background publishing, keep Ttl longer than your longest render.

Checklist

  1. Create the container, bucket or folder before the first publish.
  2. Build each provider configuration once, register it, and give the same object to TargetConfig and to CloudOptions.CloudUploadConfig.
  3. Publish with TargetLocation and TargetConfig; publish into the origin store when a CDN serves it.
  4. Serve with UseDoconutCloud<THandler>(...) on the branch the viewer calls, behind UseDoconutDistributedDocumentSecurity().
  5. Turn on the same features in the publish options and in the handler's FunctionsConfig.
  6. With FirstPagePriority, set retryOn409: true in the viewer.
  7. Plan how old documents are removed: AddDoconutDistributedRetention on a file share, lifecycle rules elsewhere.

Cette page était-elle utile ?