Orchardcore temp file storage

From CrestApps/CrestApps.AgentSkills · View interactive version

Orchardcore temp file storage is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for configuring and using Orchard Core 4.0 temporary file storage. Covers ITempDirectoryProvider, DefaultTempDirectoryProvider, the OrchardCore TempDirectory Path setting, tenant-scoped temporary directories, mounting Azure Files, AWS EFS or FSx and SMB or NFS shares, multi-instance TUS resuma

How to use this skill

Skill file

Orchard Core Temporary File Storage - Prompt Templates

Relocate and Use Temporary File Storage

You are an Orchard Core expert. Generate configuration and code for Orchard Core's shared temporary file storage.

Guidelines

Configuration

{
  "OrchardCore": {
    "TempDirectory": {
      "Path": "/mnt/shared/octemp"
    }
  }
}
OrchardCore__TempDirectory__Path=/mnt/shared/octemp

The setting is global; every tenant gets its own sub-directory beneath it.

Mounting a File Share

Mount the share at the operating system or platform level, then set Path to the mount point.

# Linux or containers, Azure Files over SMB
sudo mkdir -p /mnt/octemp
sudo mount -t cifs //<account>.file.core.windows.net/<share> /mnt/octemp \
  -o vers=3.0,username=<account>,password=<storage-key>,dir_mode=0777,file_mode=0777,serverino,nosharesock,actimeo=30
# Windows
New-SmbGlobalMapping -RemotePath "\\<account>.file.core.windows.net\<share>" -Credential $cred -Persistent $true -LocalPath Z:
{ "OrchardCore": { "TempDirectory": { "Path": "Z:\\octemp" } } }

Multi-Instance TUS Uploads

With OrchardCore.Media.Tus, every chunk of an upload must reach storage that all instances share. Choose one:

  1. Set OrchardCore:TempDirectory:Path to a shared file share.
  2. Enable sticky sessions (ARR affinity, ALB stickiness, HAProxy or NGINX sticky cookies).
  3. Enable Azure Media Storage (OrchardCore.Media.Azure.Storage) or Amazon Media Storage (OrchardCore.Media.AmazonS3) together with OrchardCore.Media.Tus. Their startups replace ITusTempStore with AzureBlobTusTempStore or S3TusTempStore, so TUS partials go to object storage. Other temporary files still use Path.

Docker Compose with a shared volume:

services:
  cms:
    image: my-orchard-site
    environment:
      OrchardCore__TempDirectory__Path: /app/data/temp
    volumes:
      - octemp:/app/data/temp

volumes:
  octemp:
    # Use an NFS, Azure Files, or EFS backed volume driver for multiple instances.

Using ITempDirectoryProvider in a Module

| Member | Returns |

|---|---|

| GetRootDirectory() | The tenant-scoped root directory, created on demand. Use it as a base for tools that need a directory, such as the deployment TemporaryFileBuilder (OrchardCore.Deployment.Core). |

| GetTempFileName(string extension = null) | A unique file path (not created; the root directory is). The extension may include or omit the leading dot. |

| CreateTempSubdirectory(string prefix = null) | A newly created unique sub-directory, optionally prefixed, for extracting archives or a PhysicalFileProvider. |

using System.IO.Compression;
using Microsoft.AspNetCore.Http;
using OrchardCore.FileStorage;

namespace MyModule.Services;

public sealed class PackageImportService
{
    private readonly ITempDirectoryProvider _tempDirectoryProvider;

    public PackageImportService(ITempDirectoryProvider tempDirectoryProvider)
    {
        _tempDirectoryProvider = tempDirectoryProvider;
    }

    public async Task ImportAsync(IFormFile package, CancellationToken cancellationToken)
    {
        var archivePath = _tempDirectoryProvider.GetTempFileName(Path.GetExtension(package.FileName));
        var extractPath = _tempDirectoryProvider.CreateTempSubdirectory("import-");

        try
        {
            await using (var stream = File.Create(archivePath))
            {
                await package.CopyToAsync(stream, cancellationToken);
            }

            ZipFile.ExtractToDirectory(archivePath, extractPath);

            // Process the extracted files.
        }
        finally
        {
            File.Delete(archivePath);
            Directory.Delete(extractPath, recursive: true);
        }
    }
}

The provider only hands out paths. Create, write, and delete the files yourself; nothing tracks or expires them.

Replacing the Provider

DefaultTempDirectoryProvider is registered per tenant with TryAddSingleton. A replacement must still return real, seekable local filesystem paths that support directory enumeration, so there is no blob or S3 implementation.

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OrchardCore.FileStorage;
using OrchardCore.Modules;

namespace MyModule;

public sealed class Startup : StartupBase
{
    public override void ConfigureServices(IServiceCollection services)
    {
        // ScratchVolumeTempDirectoryProvider is your own ITempDirectoryProvider implementation.
        services.Replace(ServiceDescriptor.Singleton<ITempDirectoryProvider, ScratchVolumeTempDirectoryProvider>());
    }
}

Upgrading from 3.x

Troubleshooting

| Symptom | Check |

|---|---|

| Disk full during concurrent large uploads | Move Path to a larger volume. |

| TUS upload fails when load-balanced | Use a shared Path, sticky sessions, or a blob/S3 ITusTempStore. |

| Deployment import fails on a blob-mounted path | Object storage cannot provide seekable files; use Azure Files or EFS/FSx. |

| Permission denied creating temp files | Grant the app identity write access to the mount. |

| Warning about a unique temporary directory at startup | Local application data is unavailable to the app identity; set OrchardCore:TempDirectory:Path. |

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.