如何上传加密格式的文件上传、格式、文件

2023-09-11 08:43:06 作者:德高望重。

我开发,将文件上传到亚马逊的应用程序。 Amazon提供 方法 WithServerSideEncryptionMethod(ServerSideEncryptionMethod.AES256)对文件进行加密,但它不能正常工作。它被保存文本为纯文本。

 公共静态无效UploadFile()
{
    新计划();
    VAR键=A;
    //键= ReplaceDblSlashToSingleFwdSlash(密钥);
    //路径= ReplaceFwdSlashToBackSlash(路径);
    VAR请求=新PutObjectRequest();
    request.WithBucketName(演示)
           .WithContentBody(我是塞纳 - 马恩省库马尔)
           .WithKey(钥匙)
           .WithServerSideEncryptionMethod(ServerSideEncryptionMethod.AES256);
    //request.PutObjectProgressEvent + = displayFileProgress;
    S3Response响应= s3Client.PutObject(要求);
    response.Dispose();
}
 

解决方案

您可以使用下面的code,以检查是否被加密或不..因为AWS S3他们的对象已经解密,当他们返回给你

这样试试下面的code,以检查对象在亚马逊S3

加密

  GetObjectMetadataRequest元=新GetObjectMetadataRequest();

GetObjectMetadataResponse响应= s3Client.GetObjectMetadata(甲基);
如果(response.ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256)
{
   //你的code到这里
}
 
微博不能上传图片片显示文件格式错误怎么办

我希望这可以帮助

I am developing an application that will upload files to Amazon. Amazon provides a method WithServerSideEncryptionMethod(ServerSideEncryptionMethod.AES256) to encrypt files but it is not working. It is saving text as a plain text.

public static void UploadFile()
{
    new Program();
    var key = "a";
    //key = ReplaceDblSlashToSingleFwdSlash(key);
    //path = ReplaceFwdSlashToBackSlash(path);
    var request = new PutObjectRequest();
    request.WithBucketName("demo")
           .WithContentBody("i am achal kumar")
           .WithKey(key)
           .WithServerSideEncryptionMethod(ServerSideEncryptionMethod.AES256);
    //request.PutObjectProgressEvent += displayFileProgress;
    S3Response response = s3Client.PutObject(request);
    response.Dispose();
}

解决方案

you can use the following code to check if the is encrypted or not .. because aws s3 they already decrypt the object when they return it to you.

so try the following code to check if the object is encrypted on amazon s3

GetObjectMetadataRequest meta = new GetObjectMetadataRequest();

GetObjectMetadataResponse response = s3Client.GetObjectMetadata(meta);
if(response.ServerSideEncryptionMethod = ServerSideEncryptionMethod.AES256)
{
   // your code goes here
}

i hope this could help