{"record":{"id":"9386ef32bbb91f11","repo":"OrchardCMS/OrchardCore","slug":"error-while-copying-file-srcpath-ex-message","errorCode":null,"errorMessage":"Error while copying file '{srcPath}': {ex.Message}","messagePattern":"Error while copying file '(.+?)': (.+?)","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs","lineNumber":247,"sourceCode":"            }\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        {\n            throw new FileStoreException($\"Cannot get file stream because the file '{path}' does not exist.\");\n        }\n        catch (AmazonS3Exception ex)\n        {\n            throw new FileStoreException($\"Error getting file stream for '{path}': {ex.Message}\", ex);\n        }","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs#L229-L265","documentation":"AmazonS3Exception thrown by CopyObjectAsync during CopyFileAsync is wrapped in a FileStoreException that appends the S3 error message and preserves the inner exception. It signals S3 rejected the copy request itself (auth, permissions, limits, connectivity).","triggerScenarios":"CopyFileAsync/MoveFileAsync when CopyObjectAsync throws: AccessDenied, InvalidObjectState (archive storage class), missing kms permissions, object too large for server-side copy, network failure.","commonSituations":"IAM lacks s3:PutObject on destination, source object in GLACIER storage class, KMS-encrypted objects without kms:Decrypt/Encrypt grants, 5GB server-side copy limit exceeded.","solutions":["Inspect the inner AmazonS3Exception message/error code and fix the underlying S3 permission or configuration issue.","Grant IAM permissions for s3:GetObject on source and s3:PutObject on destination.","For Glacier/archived objects, restore them first or use a multipart/manual copy via streams.","Use a multipart copy or stream-based copy for objects larger than 5 GB."],"exampleFix":"// before\nawait fileStore.CopyFileAsync(srcPath, dstPath); // throws with no context handling\n\n// after\ntry\n{\n    await fileStore.CopyFileAsync(srcPath, dstPath);\n}\ncatch (FileStoreException ex)\n{\n    _logger.LogError(ex, \"Copy of '{Src}' to '{Dst}' failed: {Msg}\", srcPath, dstPath, ex.Message);\n    throw;\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try\n{\n    await fileStore.CopyFileAsync(srcPath, dstPath);\n}\ncatch (FileStoreException ex)\n{\n    var s3Message = ex.InnerException?.Message ?? ex.Message;\n    _logger.LogError(\"Copy failed, S3 said: {S3Message}\", s3Message);\n    throw;\n}","preventionTips":["Grant IAM s3:GetObject + s3:PutObject for both source and destination prefixes.","Restore Glacier-class objects before copying.","Add kms:Decrypt/kms:Encrypt grants for KMS-encrypted buckets.","Use multipart copy for objects over 5 GB."],"tags":["s3","aws","permissions","copy-failed"],"backgroundTag":"api-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"}