public DeleteObjectAsync ( |
||
request | Container for the necessary parameters to execute the DeleteObject operation. | |
cancellationToken | System | /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// |
return | Task |
public static async System.Threading.Tasks.Task <bool> Delete(this string fileNameGuid, string _awsAccessKey, string _awsSecretKey, string _bucketName) { IAmazonS3 client; var s3Client = RegionEndpoint.USEast1; try { using (client = new Amazon.S3.AmazonS3Client(_awsAccessKey, _awsSecretKey, s3Client)) { DeleteObjectRequest request = new DeleteObjectRequest() { BucketName = _bucketName, Key = fileNameGuid, }; await client.DeleteObjectAsync(request); client.Dispose(); } } catch (Exception exception) { Logging.Log("Upload Documents failure", "S3 File upload Extension Method", exception); return(false); } return(true); }
private async Task<DeleteObjectResponse> DeleteItemAsync(AmazonS3Client s3Client, string bucketName, string path, CancellationToken token) { var request = new DeleteObjectRequest() { BucketName = bucketName, Key = path + _itemChange.Item.Path }; return await s3Client.DeleteObjectAsync(request, token); }
/// <summary> /// https://docs.aws.amazon.com/AmazonS3/latest/dev/DeletingOneObjectUsingNetSDK.html /// </summary> /// <param name="keyName"></param> /// <returns></returns> async Task DeleteObjectNonVersionedBucketAsync(string keyName) { var deleteObjectRequest = new DeleteObjectRequest { BucketName = awsBucket, Key = keyName }; LOGINFO("Deleting S3 Object, Key=" + keyName); await s3Client.DeleteObjectAsync(deleteObjectRequest); }
public void Delete(string key) { Amazon.S3.AmazonS3Client client = getS3Client(); var resTask = client.DeleteObjectAsync(new Amazon.S3.Model.DeleteObjectRequest() { BucketName = bucketName, Key = key }); resTask.Wait(); if (resTask.Result.HttpStatusCode != System.Net.HttpStatusCode.OK && resTask.Result.HttpStatusCode != System.Net.HttpStatusCode.NoContent) { throw new Exception("Delete failed, error code: " + resTask.Result.HttpStatusCode, resTask.Exception); } }
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); } } } }