OrchardCMS/OrchardCore · error · FileStoreException

Error while copying file

Error message

Error while copying file '${srcPath}'

What it means

After issuing CopyObjectAsync, AwsFileStorage checks the response with IsSuccessful(); if S3 did not report success it throws FileStoreException 'Error while copying file'. This catches copy attempts that complete the HTTP call but report a failed copy result.

Solutions

  1. Retry the copy operation; transient S3 issues often resolve on a second attempt.
  2. Verify the source object still exists and is not being written concurrently.
  3. Check S3 service health and region configuration.
  4. Fall back to a manual copy: GetFileStreamAsync(src) + CreateFileFromStreamAsync(dst, stream).

Example fix

// before
await fileStore.CopyFileAsync(srcPath, dstPath);

// after
try
{
    await fileStore.CopyFileAsync(srcPath, dstPath);
}
catch (FileStoreException)
{
    using var stream = await fileStore.GetFileStreamAsync(srcPath);
    await fileStore.CreateFileFromStreamAsync(dstPath, stream);
}
Defensive patterns

Strategy: retry

Try / catch

for (var attempt = 0; attempt < 3; attempt++)
{
    try { await fileStore.CopyFileAsync(srcPath, dstPath); break; }
    catch (FileStoreException) when (attempt < 2) { await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, attempt))); }
}

Prevention

When it happens

Trigger: CopyObjectAsync returns a non-successful response (e.g. 3xx/4xx/5xx result carried in the response rather than as an exception) during CopyFileAsync or MoveFileAsync.

Common situations: Large objects hitting copy limits, source object modified mid-copy, S3-side replica/region issues, proxy or gateway returning non-200 responses without raising an exception.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/30e2204bf6344579. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs:241

                Prefix = this.Combine(_basePrefix, dstPath),
            });

            if (listObjects.S3Objects?.Count > 0)
            {
                throw new ExistsFileStoreException($"Cannot copy file '{srcPath}' because a file already exists in the new path '{dstPath}'.");
            }

            var copyObjectResponse = await _amazonS3Client.CopyObjectAsync(new CopyObjectRequest
            {
                SourceBucket = _options.BucketName,
                SourceKey = this.Combine(_basePrefix, srcPath),
                DestinationBucket = _options.BucketName,
                DestinationKey = this.Combine(_basePrefix, dstPath),
            });

            if (!copyObjectResponse.IsSuccessful())
            {
                throw new FileStoreException($"Error while copying file '{srcPath}'");
            }

        }
        catch (AmazonS3Exception ex)
        {
            throw new FileStoreException($"Error while copying file '{srcPath}': {ex.Message}", ex);
        }
    }

    public Task<Stream> GetFileStreamAsync(string path)
    {
        try
        {
            var transferUtility = new TransferUtility(_amazonS3Client);
            return transferUtility.OpenStreamAsync(_options.BucketName, this.Combine(_basePrefix, path));
        }
        catch (AmazonS3Exception ex) when (ex.StatusCode == HttpStatusCode.NotFound)
        {

View on GitHub (pinned to 4306c0717f)