简体   繁体   English

需要使用c#实现AWS S3存储桶文件上传。 文件大小不受限制

[英]Need to implementation AWS S3 Bucket file upload using c#. Whereas file size is not limit

i have a requirement to upload file in AWS S3 bucket using c#, In which i have list of file to upload one time. 我需要使用c#在AWS S3存储桶中上传文件,其中我有一次要上传的文件列表。 My client send me only that for 我的客户只寄给我

( S3 : arn:aws:iam::3**********9:user/intl-in-livestreaming-user-prod) (S3:arn:aws:iam :: 3 ********** 9:user / intl-livestreaming-user-prod)

credential.After upload file create URL of that file to seen from anywhere or download it through link. 上载文件后,请创建该文件的URL以从任何地方查看或通过链接下载它。 Help me because i have no any idea about that first time i get that AWS work. 帮帮我,因为我第一次获得AWS的工作我一无所知。

In order to upload a file to your bucket in Amazon S3, you would need to import their AWSSDK package from your Nuget manager. 为了将文件上传到Amazon S3中的存储桶,您需要从Nuget管理器导入其AWSSDK软件包。 Once you have done that, you can use this piece of code to get your file uploaded. 完成此操作后,您可以使用这段代码来上传文件。 Please note that you would require the awsAccessKeyId , awsSecretAccessKey and the region endpoint when you setup your AmazonS3Client object. 请注意,设置AmazonS3Client对象时,将需要awsAccessKeyIdawsSecretAccessKey和区域终端节点。 Once you do that, you would require the name of the bucket you want to upload your file to. 完成此操作后,您将需要将文件上传到其中的存储桶的名称。 Please ensure that the bucket has the required access to accept files from outside source. 请确保存储桶具有所需的访问权限,以接受来自外部源的文件。

using Amazon.S3;
using Amazon;
using Amazon.S3.Transfer;

  using (var client = new AmazonS3Client("awsAccessKeyId", 
               "awsSecretAccessKey", RegionEndpoint.{yourregionendpoint}))
    {
      PutObjectRequest objReq = new PutObjectRequest
     {
         Key = "FolderName"+"/"+"ImageOne", //If you create folder inside bucket then you use key otherwise without key also upload data successfully.
         FilePath = "E:\\blah\\imageone.jpg",
         BucketName = "your bucket name",
         CannedACL = S3CannedACL.Private,
     };

        PutObjectResponse response = s3newClient.PutObject(objReq);
        if (response.ETag != null)
           {
            string etag = response.ETag;
            string versionID = response.VersionId;
           }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM