{"record":{"id":"30e2204bf6344579","repo":"OrchardCMS/OrchardCore","slug":"error-while-copying-file-srcpath","errorCode":null,"errorMessage":"Error while copying file '${srcPath}'","messagePattern":"Error while copying file '(.+?)'","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs","lineNumber":241,"sourceCode":"                Prefix = this.Combine(_basePrefix, dstPath),\n            });\n\n            if (listObjects.S3Objects?.Count > 0)\n            {\n                throw new ExistsFileStoreException($\"Cannot copy file '{srcPath}' because a file already exists in the new path '{dstPath}'.\");\n            }\n\n            var copyObjectResponse = await _amazonS3Client.CopyObjectAsync(new CopyObjectRequest\n            {\n                SourceBucket = _options.BucketName,\n                SourceKey = this.Combine(_basePrefix, srcPath),\n                DestinationBucket = _options.BucketName,\n                DestinationKey = this.Combine(_basePrefix, dstPath),\n            });\n\n            if (!copyObjectResponse.IsSuccessful())\n            {\n                throw new FileStoreException($\"Error while copying file '{srcPath}'\");\n            }\n\n        }\n        catch (AmazonS3Exception ex)\n        {\n            throw new FileStoreException($\"Error while copying file '{srcPath}': {ex.Message}\", ex);\n        }\n    }\n\n    public Task<Stream> GetFileStreamAsync(string path)\n    {\n        try\n        {\n            var transferUtility = new TransferUtility(_amazonS3Client);\n            return transferUtility.OpenStreamAsync(_options.BucketName, this.Combine(_basePrefix, path));\n        }\n        catch (AmazonS3Exception ex) when (ex.StatusCode == HttpStatusCode.NotFound)\n        {","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs#L223-L259","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Retry the copy operation; transient S3 issues often resolve on a second attempt.","Verify the source object still exists and is not being written concurrently.","Check S3 service health and region configuration.","Fall back to a manual copy: GetFileStreamAsync(src) + CreateFileFromStreamAsync(dst, stream)."],"exampleFix":"// before\nawait fileStore.CopyFileAsync(srcPath, dstPath);\n\n// after\ntry\n{\n    await fileStore.CopyFileAsync(srcPath, dstPath);\n}\ncatch (FileStoreException)\n{\n    using var stream = await fileStore.GetFileStreamAsync(srcPath);\n    await fileStore.CreateFileFromStreamAsync(dstPath, stream);\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for (var attempt = 0; attempt < 3; attempt++)\n{\n    try { await fileStore.CopyFileAsync(srcPath, dstPath); break; }\n    catch (FileStoreException) when (attempt < 2) { await Task.Delay(TimeSpan.FromSeconds(Math.Pow(2, attempt))); }\n}","preventionTips":["Wrap S3 mutations in a retry policy with exponential backoff.","Verify object size; use stream-based copy for very large files.","Watch AWS service health for regional incidents."],"tags":["s3","aws","copy-failed"],"backgroundTag":"http-error-response","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}