文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK CreatePresignedPost
配合使用
以下代码示例演示了如何使用 CreatePresignedPost
。
- .NET
-
- 适用于 .NET 的 SDK (v4)
-
注意
还有更多相关信息 GitHub。在 AWS 代码示例存储库
中查找完整示例,了解如何进行设置和运行。 创建预签名的帖子网址。
/// <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); }
-
有关 API 的详细信息,请参阅 适用于 .NET 的 AWS SDK API 参考CreatePresignedPost中的。
-
CreateMultipartUpload
DeleteBucket