private static async Task TestObjectACLTestAsync() { try { // Retrieve the ACL for the object. GetACLResponse aclResponse = await client.GetACLAsync(new GetACLRequest { BucketName = bucketName, Key = keyName }); S3AccessControlList acl = aclResponse.AccessControlList; // Retrieve the owner (we use this to re-add permissions after we clear the ACL). Owner owner = acl.Owner; // Clear existing grants. acl.Grants.Clear(); // Add a grant to reset the owner's full permission (the previous clear statement removed all permissions). S3Grant fullControlGrant = new S3Grant { Grantee = new S3Grantee { CanonicalUser = owner.Id }, Permission = S3Permission.FULL_CONTROL }; // Describe the grant for the permission using an email address. S3Grant grantUsingEmail = new S3Grant { Grantee = new S3Grantee { EmailAddress = emailAddress }, Permission = S3Permission.WRITE_ACP }; acl.Grants.AddRange(new List <S3Grant> { fullControlGrant, grantUsingEmail }); // Set a new ACL. PutACLResponse response = await client.PutACLAsync(new PutACLRequest { BucketName = bucketName, Key = keyName, AccessControlList = acl }); } catch (AmazonS3Exception amazonS3Exception) { Console.WriteLine("An AmazonS3Exception was thrown. Exception: " + amazonS3Exception.ToString()); } catch (Exception e) { Console.WriteLine("Exception: " + e.ToString()); } }
static void WriteObjectAcl() { string id = Common.InputString("Key:", null, false); string owner = Common.InputString("Owner:", "default", false); try { PutACLRequest request = new PutACLRequest { BucketName = _Bucket, Key = id }; request.Key = id; request.AccessControlList = new S3AccessControlList(); request.AccessControlList.Owner = new Owner(); request.AccessControlList.Owner.DisplayName = owner; request.AccessControlList.Grants = new List <S3Grant>(); S3Grant grant = new S3Grant(); S3Grantee grantee = new S3Grantee(); grantee.CanonicalUser = owner; grantee.DisplayName = owner; grantee.EmailAddress = owner; grant.Grantee = grantee; request.AccessControlList.Grants.Add(grant); PutACLResponse response = _S3Client.PutACLAsync(request).Result; int statusCode = (int)response.HttpStatusCode; if (response != null) { Console.WriteLine("Success"); return; } else { Console.WriteLine("Failed"); return; } } catch (Exception e) { Console.WriteLine(Common.SerializeJson(e, true)); } }
//public async Task PreCreate(String Title, string Description, int CategoryId, IFormFile FileName) public async Task <IActionResult> PreCreate(String Title, string Description, string CategoryName, int CategoryId, IFormFile FileName) { Movie movie = new Movie(); movie.Title = Title; movie.description = Description; movie.CategoryId = CategoryId; movie.FileName = FileName.FileName.ToString(); movie.Downloads = 0; movie.UploadDate = DateTime.Now; movie.User = this.User.Identity.Name; if (ModelState.IsValid) { _context.Add(movie); await _context.SaveChangesAsync(); ///////////////////////////////////////////////// //File transfering from user station to S3 Bucket ///////////////////////////////////////////////// var temp = Path.GetTempFileName(); using (var stream = new FileStream(temp, FileMode.Create)) { FileName.CopyTo(stream); } keyName = FileName.FileName; filePath = temp; UpLoadFileAsync().Wait(); S3CannedACL acl = S3CannedACL.PublicRead; PutACLResponse response = await s3Client.PutACLAsync(new PutACLRequest { BucketName = bucketName, Key = keyName, CannedACL = acl }); /* End of transfering *////////////////////////// return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Set <Category>(), "CategoryId", "CategoryName", movie.CategoryId); return(View(movie)); }
public static async void ChangeFilePermission(string awsAccessKeyId, string awsSecretAccessKey, RegionEndpoint region, string bucketName, string keyName, S3CannedACL permission) { try { IAmazonS3 s3Client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey, region); PutACLRequest request = new PutACLRequest() { CannedACL = permission, BucketName = bucketName, Key = keyName }; PutACLResponse response1 = await s3Client.PutACLAsync(request); Debug.WriteLine("Change Permission Complete"); } catch (AmazonS3Exception ex) { Debug.WriteLine("Exception occur when Change Permission: '{0}'", ex.Message); } }
static void WriteBucketAcl() { string id = Common.InputString("Bucket:", null, false); string owner = Common.InputString("Owner:", "default", false); PutACLRequest request = new PutACLRequest(); request.BucketName = id; request.AccessControlList = new S3AccessControlList(); request.AccessControlList.Owner = new Owner(); request.AccessControlList.Owner.DisplayName = owner; request.AccessControlList.Grants = new List <S3Grant>(); S3Grant grant = new S3Grant(); S3Grantee grantee = new S3Grantee(); grantee.CanonicalUser = owner; grantee.DisplayName = owner; grant.Grantee = grantee; request.AccessControlList.Grants.Add(grant); PutACLResponse response = _S3Client.PutACLAsync(request).Result; int statusCode = (int)response.HttpStatusCode; if (response != null) { Console.WriteLine("Success"); return; } else { Console.WriteLine("Failed"); return; } }
public void AclSamples() { { #region PutACL Sample 1 // Create a client AmazonS3Client client = new AmazonS3Client(); // Set Canned ACL (PublicRead) for an existing item client.PutACL(new PutACLRequest { BucketName = "SampleBucket", Key = "Item1", CannedACL = S3CannedACL.PublicRead }); // Set Canned ACL (PublicRead) for an existing item // (This reverts ACL back to default for object) client.PutACL(new PutACLRequest { BucketName = "SampleBucket", Key = "Item1", CannedACL = S3CannedACL.Private }); #endregion } { #region GetACL\PutACL Samples // Create a client AmazonS3Client client = new AmazonS3Client(); // Retrieve ACL for object S3AccessControlList acl = client.GetACL(new GetACLRequest { BucketName = "SampleBucket", Key = "Item1", }).AccessControlList; // Retrieve owner Owner owner = acl.Owner; // Describe grant S3Grant grant = new S3Grant { Grantee = new S3Grantee { EmailAddress = "*****@*****.**" }, Permission = S3Permission.WRITE_ACP }; // Create new ACL S3AccessControlList newAcl = new S3AccessControlList { Grants = new List <S3Grant> { grant }, Owner = owner }; // Set new ACL PutACLResponse response = client.PutACL(new PutACLRequest { BucketName = "SampleBucket", Key = "Item1", AccessControlList = acl }); #endregion } }
static async Task AddACLToExistingObjectAsync(string bucketName, string keyName) { // Retrieve the ACL for an object. GetACLResponse aclResponse = await client.GetACLAsync(new GetACLRequest { BucketName = bucketName, Key = keyName }); S3AccessControlList acl = aclResponse.AccessControlList; // Retrieve the owner. Owner owner = acl.Owner; // Clear existing grants. acl.Grants.Clear(); // Add a grant to reset the owner's full permission // (the previous clear statement removed all permissions). S3Grant fullControlGrant = new S3Grant { Grantee = new S3Grantee { CanonicalUser = acl.Owner.Id } }; acl.AddGrant(fullControlGrant.Grantee, S3Permission.FULL_CONTROL); // Specify email to identify grantee for granting permissions. S3Grant grantUsingEmail = new S3Grant { Grantee = new S3Grantee { EmailAddress = emailAddress }, Permission = S3Permission.WRITE_ACP }; // Specify log delivery group as grantee. S3Grant grantLogDeliveryGroup = new S3Grant { Grantee = new S3Grantee { URI = "http://acs.amazonaws.com/groups/s3/LogDelivery" }, Permission = S3Permission.WRITE }; // Create a new ACL. S3AccessControlList newAcl = new S3AccessControlList { Grants = new List <S3Grant> { grantUsingEmail, grantLogDeliveryGroup }, Owner = owner }; // Set the new ACL. PutACLResponse response = await client.PutACLAsync(new PutACLRequest { BucketName = bucketName, Key = keyName, AccessControlList = newAcl }); }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { PutACLResponse response = new PutACLResponse(); return(response); }
public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context) { PutACLResponse response = new PutACLResponse(); return response; }