AWS SDK Version 4 for .NET
API Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Represents a "starts-with" condition in an S3 POST policy.

Inheritance Hierarchy

System.Object
  Amazon.S3.Model.S3PostCondition
    Amazon.S3.Model.StartsWithCondition

Namespace: Amazon.S3.Model
Assembly: AWSSDK.S3.dll
Version: 3.x.y.z

Syntax

C#
public class StartsWithCondition : S3PostCondition

The StartsWithCondition type exposes the following members

Constructors

NameDescription
Public Method StartsWithCondition(string, string)

Initializes a new instance of the Amazon.S3.Model.StartsWithCondition class.

Properties

NameTypeDescription
Public Property FieldName System.String

Gets the name of the form field whose value must start with the specified prefix.

Public Property Prefix System.String

Gets the prefix that the form field value must start with.

Methods

Note:

Asynchronous operations (methods ending with Async) in the table below are for .NET 4.7.2 or higher.

NameDescription
Public Method WriteToJsonWriter(Utf8JsonWriter)

Writes this condition to the specified JSON writer as an array representing the starts-with condition.

Examples

// Only allow uploads to the "user-uploads/" prefix
var condition = new StartsWithCondition("key", "user-uploads/");
            
// Restrict uploads to a specific user's folder
var userCondition = new StartsWithCondition("key", $"users/{userId}/");
            
// Allow uploads with specific metadata prefix
var metadataCondition = new StartsWithCondition("x-amz-meta-category", "photo-");
            

Remarks

A starts-with condition requires that a form field value begins with the specified prefix. This is particularly useful for restricting object keys to specific prefixes, allowing organized uploads while maintaining flexibility in naming.

The condition is serialized as a JSON array: ["starts-with", "$fieldName", "prefix"]

The field name is automatically prefixed with "$" to indicate it's a variable reference in the POST policy. This is required by the S3 POST policy format.

Common use cases include:

Restricting uploads to a user folder: new StartsWithCondition("key", "users/johndoe/")Organizing by file type: new StartsWithCondition("key", "images/")Enforcing naming conventions: new StartsWithCondition("key", "uploads-2023-")

Version Information

.NET:
Supported in: 8.0 and newer, Core 3.1

.NET Standard:
Supported in: 2.0

.NET Framework:
Supported in: 4.7.2 and newer