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 content length range condition in an S3 POST policy.

Inheritance Hierarchy

System.Object
  Amazon.S3.Model.S3PostCondition
    Amazon.S3.Model.ContentLengthRangeCondition

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

Syntax

C#
public class ContentLengthRangeCondition : S3PostCondition

The ContentLengthRangeCondition type exposes the following members

Constructors

NameDescription
Public Method ContentLengthRangeCondition(Int64, Int64)

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

Properties

NameTypeDescription
Public Property MaximumLength System.Int64

Gets the maximum allowed file size in bytes.

Public Property MinimumLength System.Int64

Gets the minimum allowed file size in bytes.

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 content-length-range condition.

Examples

// Allow files between 1KB and 5MB (typical for profile images)
var imageSize = new ContentLengthRangeCondition(1024, 5 * 1024 * 1024);
            
// Allow documents up to 10MB
var documentSize = new ContentLengthRangeCondition(0, 10 * 1024 * 1024);
            
// Require non-empty files with reasonable maximum
var nonEmptySize = new ContentLengthRangeCondition(1, 100 * 1024 * 1024);
            

Remarks

A content length range condition restricts the size of files that can be uploaded through the presigned POST request.

The condition is serialized as a JSON array: ["content-length-range", minimumLength, maximumLength]

Both minimum and maximum values are specified in bytes and are inclusive bounds. The uploaded file size must be greater than or equal to the minimum and less than or equal to the maximum.

Common use cases include:

Profile photos: new ContentLengthRangeCondition(1024, 5 * 1024 * 1024) (1KB to 5MB)Document uploads: new ContentLengthRangeCondition(0, 10 * 1024 * 1024) (up to 10MB)Preventing empty files: new ContentLengthRangeCondition(1, long.MaxValue)

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