public async Task DeleteAsync(string key, ILog log) { if (String.IsNullOrWhiteSpace(key)) { throw new ArgumentOutOfRangeException("key"); } key = key.Trim(); if (String.IsNullOrWhiteSpace(_config.BucketName)) { throw new ArgumentOutOfRangeException("config.BucketName"); } // Delete the object string objectKey = String.Format("{0}{1}", _config.Prefix, key); var s3Client = CreateS3Client(); log.Log(LogLevels.Info, "Deleting {0} from s3://{1}/{2}", key, _config.BucketName, objectKey); var request = new Amazon.S3.Model.DeleteObjectRequest() { BucketName = _config.BucketName, Key = objectKey }; var response = await s3Client.DeleteObjectAsync(request); }
private async Task LeaveGym(Facility facilityView, ApplicationUser user, Facility facility, List <UsersInGymDetail> facilityDetails, UsersInGymDetail currentFacilityDetailDb) { user.IsInsideGym = false; // if it is not 0 then we can decrement to avoid negatives if (facility.NumberOfClientsInGym != 0) { facility.NumberOfClientsInGym--; } // adjust all variables to update the user to a left gym status if (user.WillUseWeightsRoom) { facility.NumberOfClientsUsingWeightRoom--; user.WillUseWeightsRoom = false; } if (user.WillUseCardioRoom && facility.NumberOfClientsUsingCardioRoom != 0) { facility.NumberOfClientsUsingCardioRoom--; user.WillUseCardioRoom = false; } if (user.WillUseStretchRoom && facility.NumberOfClientsUsingStretchRoom != 0) { facility.NumberOfClientsUsingStretchRoom--; user.WillUseWeightsRoom = false; } // if there are entries for facilities, loop through all the facilities, remove the entry which is stamped with the current user entry if (facilityDetails.Count() > 0) { _facilityContext.UsersInGymDetails.Remove(currentFacilityDetailDb); } facilityView.IsCameraScanSuccessful = false; user.IsWithin10m = false; user.IsCameraScanSuccessful = false; user.AccessGrantedToFacility = false; // delete detected image from S3 bucket try { string keyName = $"{user.FirstName}_{user.Id}.jpg"; var deleteObjectRequest = new Amazon.S3.Model.DeleteObjectRequest { BucketName = bucket, Key = keyName }; await S3Client.DeleteObjectAsync(deleteObjectRequest); } catch (AmazonS3Exception e) { _logger.LogInformation(e.Message); } catch (Exception e) { _logger.LogInformation(e.Message); } }
Task Delete(Amazon.S3.Model.S3Object item) { var request = new Amazon.S3.Model.DeleteObjectRequest { BucketName = item.BucketName, Key = item.Key }; return(S3Client.DeleteObjectAsync(request)); }
public async Task DeleteFile(string filePath, CancellationToken cancellationToken) { var client = GetClient(); var request = new Amazon.S3.Model.DeleteObjectRequest(); request.BucketName = _bucketName; request.Key = filePath; await client.DeleteObjectAsync(request, cancellationToken); }
/// <summary> /// Deletes a file from s3. /// </summary> /// <param name="keyName">Name of the key.</param> public void DeleteFromS3(string keyName) { var deleteObjectRequest = new Amazon.S3.Model.DeleteObjectRequest { BucketName = s3Settings.BucketName, Key = keyName }; s3Client.DeleteObject(deleteObjectRequest); }
public void DeleteItem(string bucketName, string keyName) { //ref: http://docs.aws.amazon.com/AmazonS3/latest/dev/DeletingOneObjectUsingNetSDK.html var region = Amazon.RegionEndpoint.GetBySystemName(this.Credential.Region); using (var client = new Amazon.S3.AmazonS3Client(this.Credential.AcesssKey, this.Credential.SecretKey, region)) { var deleteObjectRequest = new Amazon.S3.Model.DeleteObjectRequest { BucketName = bucketName, Key = keyName }; client.DeleteObject(deleteObjectRequest); Log(string.Format("AwsS3 -- Deleted {0}", keyName)); } }
public async Task EditFile(string filePath, string contentType, string content) { #pragma warning disable 618 // "'StoredProfileCredentials' is obsolete..." var creds = new StoredProfileAWSCredentials("acmesharp-tests"); #pragma warning restore 618 var reg = RegionEndpoint.GetBySystemName(AwsRegion); var delete = content == null; // We need to strip off any leading '/' in the path or // else it creates a path with an empty leading segment // if (filePath.StartsWith("/")) // filePath = filePath.Substring(1); filePath = filePath.Trim('/'); using (var s3 = new Amazon.S3.AmazonS3Client(creds, reg)) { if (delete) { var s3Requ = new Amazon.S3.Model.DeleteObjectRequest { BucketName = BucketName, Key = filePath, }; var s3Resp = await s3.DeleteObjectAsync(s3Requ); } else { using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(content))) { var s3Requ = new Amazon.S3.Model.PutObjectRequest { BucketName = BucketName, Key = filePath, ContentType = contentType, InputStream = ms, CannedACL = S3CannedAcl, }; var s3Resp = await s3.PutObjectAsync(s3Requ); } } } }
public static void Execute( request m, out HttpStatusCode hsc, out string status, string awsAccessKey, string awsSecretKey ) { hsc = HttpStatusCode.BadRequest; status = ""; try { using (var s3c = new AmazonS3Client(awsAccessKey, awsSecretKey, m.re)) { var request = new Amazon.S3.Model.DeleteObjectRequest { BucketName = m.bucketName, Key = m.key, }; var dor = s3c.DeleteObjectAsync(request).Result; hsc = dor.HttpStatusCode == System.Net.HttpStatusCode.NoContent ? HttpStatusCode.OK : HttpStatusCode.BadRequest ; } return; } catch (Exception ex) { LogIt.E(ex); hsc = HttpStatusCode.InternalServerError; status = "unexecpected error"; return; } finally { LogIt.I(JsonConvert.SerializeObject( new { hsc, status, m, //ipAddress = GetPublicIpAddress.Execute(hc), //executedBy = GetExecutingUsername.Execute() }, Formatting.Indented)); } }
private void RenameContent(string oldContentName, string newContentName) { var copyObjectRequest = new Amazon.S3.Model.CopyObjectRequest() { SourceBucket = _bucketName, SourceKey = MakeKey(oldContentName), DestinationBucket = _bucketName, DestinationKey = MakeKey(newContentName) }; _amazonS3.CopyObjectAsync(copyObjectRequest).Wait(); var deleteObjectRequest = new Amazon.S3.Model.DeleteObjectRequest() { BucketName = _bucketName, Key = MakeKey(oldContentName) }; _amazonS3.DeleteObjectAsync(deleteObjectRequest).Wait(); }
public bool RemoveFile(string key) { try { var delRequest = new Amazon.S3.Model.DeleteObjectRequest() .WithBucketName(Helper.AppConfig.AWS_Bucket) .WithKey(key); S3Helper.S3ClientInstance.DeleteObject(delRequest); } catch { return false; } return true; }
public ActionResult DeleteConfirmed(string id, string prefix = "", int maxKeys = 100) { ViewBag.prefix = prefix; ViewBag.maxKeys = maxKeys; var delete = new Amazon.S3.Model.DeleteObjectRequest(); delete.WithBucketName(WebConfigurationManager.AppSettings["UploadBucket"]); delete.WithKey(id); s3.DeleteObject(delete); return RedirectToAction("Index", new { prefix = prefix, maxKeys = maxKeys }); }