Amazon S3 upload with public permissions

前端 未结 5 1726
再見小時候
再見小時候 2021-02-01 03:15

I\'m using the Amazon C# SDK and trying to upload a file, but by default it has restricted permissions. I would like to make it publicly available, but I can\'t seem to find ou

5条回答
  •  执念已碎
    2021-02-01 04:16

    Consider CannedACL approach, shown in the follwing snippet:

            string filePath = @"Path\Desert.jpg";
            Stream input = new FileStream(filePath, FileMode.Open);
            PutObjectRequest request2 = new PutObjectRequest();
            request2.WithMetaData("title", "the title")
                .WithBucketName(bucketName)
                .WithCannedACL(S3CannedACL.PublicRead)
                .WithKey(keyName)
                .WithInputStream(input);
    

提交回复
热议问题