对象相关接口 返回结果 生成对应的预签名上传 URL,该链接允许用户在指定的时间内直接将对象上传到媒体存储存储桶。 服务端加密 功能说明 上传对象时可以指定对象的加密算法,即使设置桶的加密配置也可以加密请求上传的对象数据,服务端根据指定的加密算法对对象数据进行加密。目前支持AES256和国密SM4加密算法。 代码示例 plaintext using System; using System.Threading.Tasks; using Amazon.Runtime; using Amazon.S3; using Amazon.S3.Model; namespace DotNetSDK.ObjectOperation { public class PutObjectWithEncryptionExample { public static async Task PutObjectWithEncryption() { var accessKey " "; var secretKey " "; var endpoint " "; var bucketName " "; var key " "; var filePath " "; try { var credentials new BasicAWSCredentials(accessKey, secretKey); var conf new AmazonS3Config { ServiceURL endpoint, UseHttp false }; var s3Client new AmazonS3Client(credentials, conf); var putObjectRequest new PutObjectRequest() { BucketName bucketName, Key key, FilePath filePath, ServerSideEncryptionMethod new ServerSideEncryptionMethod("AES256") }; var result await s3Client.PutObjectAsync(putObjectRequest); if (result.HttpStatusCode ! System.Net.HttpStatusCode.OK) { Console.WriteLine("fail to put object {0}, HttpStatusCode:{1}, ErrorCode:{2}.", key, (int) result.HttpStatusCode, result.HttpStatusCode); return; } Console.WriteLine("object ETag:{0}, object versionId:{1}", result.ETag, result.VersionId); Console.WriteLine("encryption method:{0}", result.ServerSideEncryptionMethod.Value); } catch (Exception e) { Console.WriteLine(e.Message); } } } } 请求参数 加密参数说明如下: 参数 类型 说明 是否必要 ServerSideEncryptionMethod ServerSideEncryptionMethod 指定服务端采用的加密算法,如AES256、SM4 否
来自: