Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Utilizzare CreatePresignedPostcon un AWS SDK
Il seguente esempio di codice mostra come utilizzareCreatePresignedPost.
- .NET
-
- SDK per .NET (v4)
-
Crea un URL POST prefirmato.
/// <summary>
/// Create a presigned POST URL with conditions.
/// </summary>
/// <param name="s3Client">The Amazon S3 client.</param>
/// <param name="bucketName">The name of the bucket.</param>
/// <param name="objectKey">The object key (path) where the uploaded file will be stored.</param>
/// <param name="expires">When the presigned URL expires.</param>
/// <param name="fields">Dictionary of fields to add to the form.</param>
/// <param name="conditions">List of conditions to apply.</param>
/// <returns>A CreatePresignedPostResponse object with URL and form fields.</returns>
public async Task<CreatePresignedPostResponse> CreatePresignedPostAsync(
IAmazonS3 s3Client,
string bucketName,
string objectKey,
DateTime expires,
Dictionary<string, string>? fields = null,
List<S3PostCondition>? conditions = null)
{
var request = new CreatePresignedPostRequest
{
BucketName = bucketName,
Key = objectKey,
Expires = expires
};
// Add custom fields if provided
if (fields != null)
{
foreach (var field in fields)
{
request.Fields.Add(field.Key, field.Value);
}
}
// Add conditions if provided
if (conditions != null)
{
foreach (var condition in conditions)
{
request.Conditions.Add(condition);
}
}
return await s3Client.CreatePresignedPostAsync(request);
}
Per un elenco completo delle guide per sviluppatori AWS SDK e degli esempi di codice, consultaSviluppo con Amazon S3 utilizzando AWS SDK. Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell’SDK.