繁体   English   中英

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

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

我需要使用c#在AWS S3存储桶中上传文件,其中我有一次要上传的文件列表。 我的客户只寄给我

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

上载文件后,请创建该文件的URL以从任何地方查看或通过链接下载它。 帮帮我,因为我第一次获得AWS的工作我一无所知。

为了将文件上传到Amazon S3中的存储桶,您需要从Nuget管理器导入其AWSSDK软件包。 完成此操作后,您可以使用这段代码来上传文件。 请注意,设置AmazonS3Client对象时,将需要awsAccessKeyIdawsSecretAccessKey和区域终端节点。 完成此操作后,您将需要将文件上传到其中的存储桶的名称。 请确保存储桶具有所需的访问权限,以接受来自外部源的文件。

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