{"record":{"id":"8be0d146cb91ac38","repo":"OrchardCMS/OrchardCore","slug":"cannot-create-file-path","errorCode":null,"errorMessage":"Cannot create file '{path}'","messagePattern":"Cannot create file '(.+?)'","errorType":"exception","errorClass":"FileStoreException","httpStatus":null,"severity":"error","filePath":"src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs","lineNumber":300,"sourceCode":"                    Prefix = this.Combine(_basePrefix, path),\n                });\n\n                if (listObjects.S3Objects?.Count > 0)\n                {\n                    throw new ExistsFileStoreException($\"Cannot create file '{path}' because it already exists.\");\n                }\n            }\n\n            var response = await _amazonS3Client.PutObjectAsync(new PutObjectRequest\n            {\n                BucketName = _options.BucketName,\n                Key = this.Combine(_basePrefix, path),\n                InputStream = inputStream,\n            });\n\n            if (!response.IsSuccessful())\n            {\n                throw new FileStoreException($\"Cannot create file '{path}'\");\n            }\n        }\n        catch (AmazonS3Exception ex)\n        {\n            throw new FileStoreException($\"Cannot create file '{path}', S3 service threw an exception: {ex.Message}\");\n        }\n\n        return path;\n    }\n\n    private static string NormalizePrefix(string prefix)\n    {\n        prefix = prefix.Trim('/') + '/';\n        if (prefix.Length == 1)\n        {\n            return string.Empty;\n        }\n","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore/OrchardCore.FileStorage.AmazonS3/AwsFileStorage.cs#L282-L318","documentation":"After PutObjectAsync completes, CreateFileFromStreamAsync checks response.IsSuccessful(); a non-successful response raises FileStoreException 'Cannot create file'. Additionally, any AmazonS3Exception during upload is wrapped as 'Cannot create file ..., S3 service threw an exception'. It signals the upload to S3 failed.","triggerScenarios":"CreateFileFromStreamAsync when PutObjectAsync returns a failed response or throws: AccessDenied, bucket not found, network interruption, payload issues, invalid credentials.","commonSituations":"IAM missing s3:PutObject, wrong bucket name, upload interrupted by network outage, request body too large or stream already consumed, throttling under heavy media upload load.","solutions":["Read the S3 error message (or inner exception) and fix credentials/IAM s3:PutObject permissions.","Verify BucketName and region configuration are correct and the bucket exists.","Ensure the input stream is positioned at 0 and not disposed before upload.","Retry failed uploads with backoff; use multipart/TransferUtility for large files."],"exampleFix":"// before\nusing var stream = File.OpenRead(localPath);\nawait fileStore.CreateFileFromStreamAsync(name, stream);\n\n// after\nusing var stream = File.OpenRead(localPath);\ntry\n{\n    await fileStore.CreateFileFromStreamAsync(name, stream, overwrite: true);\n}\ncatch (FileStoreException ex)\n{\n    _logger.LogError(ex, \"Upload of '{Name}' failed: {Msg}\", name, ex.Message);\n    throw;\n}","handlingStrategy":"retry","validationCode":"if (string.IsNullOrEmpty(_awsOptions.BucketName))\n{\n    throw new InvalidOperationException(\"S3 bucket name is not configured.\");\n}\nif (!stream.CanRead)\n{\n    throw new InvalidOperationException(\"Input stream is not readable.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await fileStore.CreateFileFromStreamAsync(path, stream);\n}\ncatch (FileStoreException ex)\n{\n    _logger.LogError(ex, \"S3 upload failed: {Message}\", ex.InnerException?.Message ?? ex.Message);\n    throw;\n}","preventionTips":["Grant IAM s3:PutObject on the target prefix.","Reset stream position to 0 and keep it open during upload.","Use TransferUtility/multipart for large files.","Retry uploads with exponential backoff on transient failures."],"tags":["s3","aws","upload","permissions"],"backgroundTag":"file-write-failed","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"}