public void Delete( string name )
 {
     using ( AmazonS3 client = AWSClientFactory.CreateAmazonS3Client( this.amazonKey, this.amazonSecret ) ) {
         DeleteObjectRequest request = new DeleteObjectRequest {
             BucketName = this.amazonBucket,
             Key = name
         };
         client.DeleteObject( request );
     }
     if ( !name.EndsWith( ".lock" ) ) {
         this.Delete( name + ".lock" );
     }
 }
Exemplo n.º 2
0
        public void DeleteObject(String bucketPath)
        {
            try
            {
                var deleteObjectRequest = new DeleteObjectRequest
                {
                    BucketName = _bucketName,
                    Key        = bucketPath
                };

                var response = _client.DeleteObjectAsync(deleteObjectRequest).Result;
            }
            catch (AmazonS3Exception e)
            {
                Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Deletes object from amazon s3
        /// </summary>
        /// <param name="objectKey"></param>
        public void DeleteObject(string objectKey)
        {
            try
            {
                using (var client = new AmazonS3Client(awsAccessKeyId, awsSecretAccessKey, Amazon.RegionEndpoint.EUWest2))
                // using (var client = new AmazonS3Client(Amazon.RegionEndpoint.EUWest2))
                {
                    var request = new DeleteObjectRequest
                    {
                        BucketName = bucketName,
                        Key        = objectKey
                    };

                    client.DeleteObject(request);
                }
            }
            catch (Exception ex)
            {
                Program.ErrorLogging(ex);
            }
        }
Exemplo n.º 4
0
        public async Task Delete(string key)
        {
            var deleteRequest = new DeleteObjectRequest
            {
                BucketName = this.BucketName,
                Key        = key
            };

            try
            {
                var response = await this.S3Client.DeleteObjectAsync(deleteRequest);

                Logger.LogInformation($"Deleted object {key} from bucket {this.BucketName}. Request Id: {response.ResponseMetadata.RequestId}");
            }
            catch (AmazonS3Exception e)
            {
                this.Response.StatusCode = (int)e.StatusCode;
                var writer = new StreamWriter(this.Response.Body);
                writer.Write(e.Message);
            }
        }
Exemplo n.º 5
0
        public async Task <bool> EliminarFoto(Trabajador t)
        {
            try
            {
                var deleteObjectRequest = new DeleteObjectRequest
                {
                    BucketName = bucketName,
                    //key es la ubicación donde se encuentra la foto
                    Key = string.Format($"fotos/trabajador/{t.IdNegocio}/{t.Rut}/foto.png"),
                };

                DeleteObjectResponse response = await awsclient.DeleteObjectAsync(deleteObjectRequest);

                return(response.HttpStatusCode == HttpStatusCode.OK);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
Exemplo n.º 6
0
        public async Task DeleteObject(string bucketName, string keyName)
        {
            try
            {
                var deleteObjectRequest = new DeleteObjectRequest
                {
                    BucketName = bucketName,
                    Key        = keyName
                };

                await client.DeleteObjectAsync(deleteObjectRequest);
            }
            catch (AmazonS3Exception e)
            {
                Console.WriteLine("Error encountered on server. Message:'{0}' when deleting an object", e.Message, keyName);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unknown encountered on server. Message:'{0}' when deleting an object", e.Message, keyName);
            }
        }
Exemplo n.º 7
0
        private async Task ProcessMessageAsync(SQSEvent.SQSMessage message, ILambdaContext context)
        {
            context.Logger.LogLine($"Processed message {message.Body}");
            DeleteObjectRequest deleteRequest = new DeleteObjectRequest()
            {
                BucketName = "taskmaster-storage",
                Key        = message.Body
            };

            DeleteObjectRequest deleteThumbnailRequest = new DeleteObjectRequest()
            {
                BucketName = "taskmaster-thumbnail",
                Key        = $"thumbnail-{message.Body}"
            };


            // TODO: Do interesting work based on the new message
            await S3Client.DeleteObjectAsync(deleteRequest);

            await S3Client.DeleteObjectAsync(deleteThumbnailRequest);
        }
Exemplo n.º 8
0
        public async Task <bool> Delete(string path)
        {
            using (var client = GetClient())
            {
                var request = new DeleteObjectRequest
                {
                    BucketName = _bucketName,

                    Key = path
                };

                var response = await client.DeleteObjectAsync(request).ConfigureAwait(false);

                if (response.HttpStatusCode != HttpStatusCode.NoContent)
                {
                    throw new Exception("HTTP " + response.HttpStatusCode);
                }

                return(true);
            }
        }
Exemplo n.º 9
0
        public bool DeleteBucketObject(string bucketName, string objectKey)
        {
            try
            {
                var request = new DeleteObjectRequest
                {
                    BucketName = bucketName,
                    Key        = objectKey
                };

                var response = GetClient().DeleteObjectAsync(request);

                Console.WriteLine(" Object {0} removed!", objectKey);

                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
        public override async Task <bool> DeleteAsync(BlobProviderDeleteArgs args)
        {
            var blobName = BlobNameCalculator.Calculate(args);

            if (await BlobExistsAsync(args, blobName))
            {
                var request = new DeleteObjectRequest(args.ContainerName, blobName);

                try
                {
                    var result = GetClient(args).DeleteObject(request);
                    return(true);
                }
                catch (Exception ee)
                {
                    return(false);
                    // throw;
                }
            }
            return(false);
        }
Exemplo n.º 11
0
        public async Task DeleteFileAsync(string fileName)
        {
            try
            {
                var deleteObjectRequest = new DeleteObjectRequest
                {
                    BucketName = _bucket,
                    Key        = fileName
                };

                var result = await _client.DeleteObjectAsync(deleteObjectRequest);
            }
            catch (AmazonS3Exception)
            {
                throw;
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 12
0
        protected void DeleteFileInner(AmazonS3Client Client, string BucketName, string Key, SemaphoreSlim Semaphore, DeleteState State)
        {
            try
            {
                Semaphore.Wait();

                DeleteObjectRequest Request = new DeleteObjectRequest();
                Request.BucketName = BucketName;
                Request.Key        = Key;
                Client.DeleteObject(Request);

                if (State != null)
                {
                    Interlocked.Increment(ref State.NumFiles);
                }
            }
            finally
            {
                Semaphore.Release();
            }
        }
Exemplo n.º 13
0
        private string DeleteFromS3(string fileName)
        {
            try
            {
                AWSCredentials      awsCredentials      = new BasicAWSCredentials(_accessKey, _secretAccess);
                AmazonS3Client      amazonS3            = new AmazonS3Client(awsCredentials, Amazon.RegionEndpoint.USWest2);
                DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest
                {
                    BucketName = _existingBucketName,
                    Key        = fileName
                };
                amazonS3.DeleteObject(deleteObjectRequest);
            }
            catch (AmazonS3Exception s3Exception)
            {
                Console.WriteLine(s3Exception.Message,
                                  s3Exception.InnerException);
            }

            return(blogPhotoKey);
        }
Exemplo n.º 14
0
        public void Delete(string domain, string path, bool quotaDelete)
        {
            using (var client = GetClient())
            {
                var key = MakePath(domain, path);
                if (quotaDelete)
                {
                    QuotaDelete(domain, client, key);
                }

                Recycle(client, domain, key);

                var request = new DeleteObjectRequest
                {
                    BucketName = _bucket,
                    Key        = key
                };

                client.DeleteObject(request);
            }
        }
Exemplo n.º 15
0
        public void DeleteFile(string fileKey)
        {
            try
            {
                DeleteObjectRequest request = new DeleteObjectRequest
                {
                    Key        = fileKey,
                    BucketName = _bucketName
                };

                DeleteObjectResponse response = _awsS3Client.DeleteObject(request);
                if (response.HttpStatusCode != System.Net.HttpStatusCode.NoContent)
                {
                    throw new ApplicationException("S3 DeleteFile - received status code " + response.HttpStatusCode.ToString() + ".");
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException("S3 DeleteFile - unexpected exception.", ex);
            }
        }
Exemplo n.º 16
0
        public async Task DeleteObjectInS3Async(string fileName)
        {
            try
            {
                var deleteObjectRequest = new DeleteObjectRequest
                {
                    BucketName = configuration["AWSS3Bucket:BucketName"],
                    Key        = $"{configuration["AWSS3Bucket:Key"]}/{fileName}",
                };

                var result = await s3Client.DeleteObjectAsync(deleteObjectRequest);
            }
            catch (AmazonS3Exception e)
            {
                throw new AmazonS3Exception($"Error encountered on server when deleting an object. Message: {e.Message}");
            }
            catch (Exception e)
            {
                throw new Exception($"Unknown encountered on server when deleting an object. Message:{e.Message}");
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Deletes "dataname" from the bucket "bucketname"
        /// </summary>
        public bool DeleteDataItem(string bucketname, string dataname)
        {
            // Reset error info
            ClearErrorInfo();

            // Delete data
            try
            {
                DeleteObjectRequest request = new DeleteObjectRequest();
                request.BucketName = bucketname;
                request.Key        = dataname;
                S3client.DeleteObject(request);
            }
            catch (Exception ex)
            {
                ErrorCode    = -1;
                ErrorMessage = ex.Message;
            }

            return(ErrorCode == 0);
        }
Exemplo n.º 18
0
        public JsonResult DeleteImageFromS3(string objectKey)
        {
            try
            {
                AmazonS3Client      s3Client = new AmazonS3Client();
                DeleteObjectRequest request  = new DeleteObjectRequest();

                request.BucketName = _awsBucketName;
                request.Key        = objectKey;

                s3Client.DeleteObject(request);
                s3Client.Dispose();

                return(Json(true));
            }
            catch (Exception ex) {
                ErrorLoggingClass errorLog = new ErrorLoggingClass();
                errorLog.logError(ex.Message, ex.Source, ex.StackTrace, "Enter Fish", "FishController", "DeleteImageFromS3", User.Identity.Name, null);
                return(Json(false));
            }
        }
Exemplo n.º 19
0
        public bool DeleteFile(string bucketName, string subDirectoryInBucket, string fileNameInS3)
        {
            bool IsComplete = true;

            #region Creating a new S3 Sub-Folder under AWS LRCA Folder
            string strAWSAccessKey = System.Configuration.ConfigurationManager.AppSettings["AWSAccessKey"];
            string strAWSSecretKey = System.Configuration.ConfigurationManager.AppSettings["AWSSecretKey"];

            AmazonS3Config config = new AmazonS3Config();
            //config.ServiceURL = "sourcespoon.s3.amazonaws.com";
            config.ServiceURL     = "testsourcespoon.s3.amazonaws.com";
            config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;

            AmazonS3Client s3Client = new AmazonS3Client(
                strAWSAccessKey,
                strAWSSecretKey,
                config
                );


            using (IAmazonS3 s3ClientInterface = s3Client)
            {
                try
                {
                    DeleteObjectRequest request = new DeleteObjectRequest();
                    request.BucketName = bucketName;
                    request.Key        = subDirectoryInBucket + "/" + fileNameInS3;
                    s3Client.DeleteObject(request);
                }
                catch (AmazonS3Exception ex)
                {
                    IsComplete = false;
                    ErrorHandler.ErrorLogging(ex, false);
                    ErrorHandler.ReadError();
                }
            }
            return(IsComplete);

            #endregion
        }
        public async void DeleteFile(string pictureUri)
        {
            if (pictureUri != null && pictureUri != "")
            {
                string[] separatingStrings = { $"https://{settings.AWSS3.BucketName}.s3.{settings.AWSS3.BucketRegion}.amazonaws.com/" };

                string[] words = pictureUri.Split(separatingStrings, System.StringSplitOptions.RemoveEmptyEntries);

                string key = "";

                foreach (var word in words)
                {
                    key = word;
                }

                try
                {
                    var region   = Amazon.RegionEndpoint.GetBySystemName(settings.AWSS3.BucketRegion);
                    var s3Client = new AmazonS3Client(settings.AWSS3.Key, settings.AWSS3.SecretKey, region);


                    DeleteObjectRequest request = new DeleteObjectRequest
                    {
                        BucketName = settings.AWSS3.BucketName,
                        Key        = key
                    };

                    DeleteObjectResponse response = await s3Client.DeleteObjectAsync(request);

                    if (response != null)
                    {
                        return;
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Exemplo n.º 21
0
        public async Task <UploadResponse> RemoveUploadedFile(String fileName)
        {
            try
            {
                var client = new AmazonS3Client(accessKey, accessSecret, Amazon.RegionEndpoint.EUCentral1);

                var request = new DeleteObjectRequest
                {
                    BucketName = bucket,
                    Key        = fileName
                };

                var response = await client.DeleteObjectAsync(request);

                if (response.HttpStatusCode == System.Net.HttpStatusCode.OK)
                {
                    return(new UploadResponse
                    {
                        HasSucceed = true,
                        FileName = fileName
                    });
                }
                else
                {
                    return(new UploadResponse
                    {
                        HasSucceed = false,
                        FileName = fileName
                    });
                }
            }
            catch (Exception ex)
            {
                return(new UploadResponse
                {
                    HasSucceed = false,
                    Message = ex.Message
                });
            }
        }
Exemplo n.º 22
0
        public bool deleteFilesInDirectory(int id)
        {
            DeleteObjectResponse response = null;
            bool ok = false;

            try
            {
                if (id > 0)
                {
                    Image image = _imagesService.Get(id);

                    if (image != null)
                    {
                        string fileNameAtAws = image.ImageUrl;

                        AWSCredentials awsCredentials = new BasicAWSCredentials(_configService.AwsAccessKeyId, _configService.AwsSecret);
                        AmazonS3Client client         = new AmazonS3Client(awsCredentials, Amazon.RegionEndpoint.USWest2);

                        DeleteObjectRequest fileDeleteRequest = new DeleteObjectRequest();
                        fileDeleteRequest.BucketName = _configService.AwsBucketName;
                        fileDeleteRequest.Key        = fileNameAtAws;

                        bool keyExists = ExistsKey(client, fileNameAtAws, fileDeleteRequest.BucketName);

                        if (keyExists)
                        {
                            response = client.DeleteObject(fileDeleteRequest);

                            ok = true;
                        }
                    }
                }
            }
            catch (AmazonS3Exception)
            {
                throw;
            }

            return(ok);
        }
Exemplo n.º 23
0
        public override void DeleteExpired(string domain, string path, TimeSpan oldThreshold)
        {
            using (var client = GetClient())
            {
                var s3Obj = GetS3Objects(domain, path);
                foreach (var s3Object in s3Obj)
                {
                    var request = new GetObjectMetadataRequest
                    {
                        BucketName = _bucket,
                        Key        = s3Object.Key
                    };

                    var metadata         = client.GetObjectMetadata(request);
                    var privateExpireKey = metadata.Metadata["private-expire"];
                    if (string.IsNullOrEmpty(privateExpireKey))
                    {
                        continue;
                    }

                    long fileTime;
                    if (!long.TryParse(privateExpireKey, out fileTime))
                    {
                        continue;
                    }
                    if (DateTime.UtcNow <= DateTime.FromFileTimeUtc(fileTime))
                    {
                        continue;
                    }
                    //Delete it
                    var deleteObjectRequest = new DeleteObjectRequest
                    {
                        BucketName = _bucket,
                        Key        = s3Object.Key
                    };

                    client.DeleteObject(deleteObjectRequest);
                }
            }
        }
Exemplo n.º 24
0
        public async Task <bool> DeleteImageAsync(AnnotationImage image)
        {
            try
            {
                // Delete image from S3
                var deleteObjectRequest = new DeleteObjectRequest
                {
                    BucketName = this._bucketName,
                    Key        = $"{image.Package.PackageName.ReplaceSpecialCharacters()}/{image.ImageName.ReplaceSpecialCharacters()}"
                };

                var response = await this._s3Client.DeleteObjectAsync(deleteObjectRequest).ConfigureAwait(false);

                // Delete image from DynamoDB
                using (var context = new DynamoDBContext(this._dynamoDbClient))
                {
                    var dbConfig = new DynamoDBOperationConfig
                    {
                        OverrideTableName = this._dbTableName
                    };
                    var package = await context.LoadAsync <AnnotationPackageDto>(image.Package.ExternalId, dbConfig).ConfigureAwait(false);

                    package.Images?.RemoveAll(o => o.ImageName.Equals(image.ImageName));
                    await context.SaveAsync(package, dbConfig).ConfigureAwait(false);
                }

                // Delete local image
                var localImagePath = Path.Combine(this._extractionFolder, image.Package.PackageName, image.ImageName);
                if (File.Exists(localImagePath))
                {
                    File.Delete(localImagePath);
                }

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
Exemplo n.º 25
0
        public void RemoveFolder(Uri uri)
        {
            CheckUri(uri);

            try
            {
                var sourceKey = HttpUtility.UrlDecode(uri.AbsolutePath).TrimStart('/');

                using (var client = CreateAmazonS3Client())
                {
                    var request = new DeleteObjectRequest()
                                  .WithKey(sourceKey)
                                  .WithBucketName(bucketName);

                    client.DeleteObject(request);
                }
            }
            catch (Exception e)
            {
                throw new StorageException(string.Format("Failed to delete object. Uri: {0}", uri), e);
            }
        }
Exemplo n.º 26
0
        public void DeleteFile(string folderName, string fileName)
        {
            //folder ignored - packages stored on top level of S3 bucket
            if (String.IsNullOrWhiteSpace(folderName))
            {
                throw new ArgumentNullException("folderName");
            }
            if (String.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException("fileName");
            }

            var request = new DeleteObjectRequest();

            request.WithBucketName(clientContext.BucketName);
            request.WithKey(fileName);

            using (AmazonS3 client = clientContext.CreateInstance())
            {
                S3Response response = WrapRequestInErrorHandler(() => client.DeleteObject(request));
            }
        }
        private static async Task DeleteObjectNonVersionedBucketAsync()
        {
            try
            {
                var deleteObjectRequest = new DeleteObjectRequest
                {
                    BucketName = bucketName,
                    Key        = keyName
                };

                Console.WriteLine("Deleting an object");
                await client.DeleteObjectAsync(deleteObjectRequest);
            }
            catch (AmazonS3Exception e)
            {
                Console.WriteLine("Error encountered on server. Message:'{0}' when writing an object", e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine("Unknown encountered on server. Message:'{0}' when writing an object", e.Message);
            }
        }
Exemplo n.º 28
0
        private void Delete(S3BucketKeyInfo bki)
        {
            var request = new DeleteObjectRequest
            {
                BucketName = bki.BucketName,
                Key        = bki.Key
            };

            try
            {
                S3Client.DeleteObject(request);
            }
            catch (AmazonS3Exception s3x)
            {
                if (IsMissingObjectException(s3x))
                {
                    return;
                }

                throw;
            }
        }
Exemplo n.º 29
0
        public void DeleteFile(string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException("key", "is null");
            }

            if (Encoding.UTF8.GetByteCount(key) > 1023)
            {
                throw new ArgumentOutOfRangeException("key", key, "too long");
            }

            using (this.client = new AmazonS3Client(accessKeyId, accessKeySecret, endpoint))
            {
                var request = new DeleteObjectRequest()
                {
                    BucketName = bucketName,
                    Key        = key,
                };
                var response = this.client.DeleteObject(request);
            }
        }
        public void delete_file(string folderName, string fileName)
        {
            // It's allowed to have an empty folder name.
            // if (String.IsNullOrWhiteSpace(folderName)) throw new ArgumentNullException("folderName");
            if (String.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentNullException("fileName");
            }

            folderName = (string.IsNullOrEmpty(folderName) ? String.Empty : folderName.Substring(folderName.Length - 1, 1) == "/" ? folderName : folderName + "/");
            fileName   = string.Format("{0}{1}", folderName, fileName);

            var request = new DeleteObjectRequest();

            request.WithBucketName(clientContext.BucketName);
            request.WithKey(fileName);

            using (AmazonS3 client = clientContext.create_instance())
            {
                S3Response response = wrap_request_in_error_handler(() => client.DeleteObject(request));
            }
        }
Exemplo n.º 31
0
        public async Task <string> DeleteFile([FromRoute] string fileName)
        {
            string result = String.Empty;
            string path   = this._defaultFolder + "/" + fileName;

            try
            {
                DeleteObjectRequest request = new DeleteObjectRequest()
                {
                    BucketName = _bucketName,
                    Key        = path               // <- in S3 key as path
                };
                DeleteObjectResponse rsponse = await this._s3Client.DeleteObjectAsync(request);

                result = string.Format($"{ this._bucketName}/{path} ");
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result);
        }
Exemplo n.º 32
0
 /// <summary>
 /// Deletes an existing object by type and id.
 /// </summary>
 /// <param name="type">Object type.</param>
 /// <param name="id">Object id for the object to be deleted.</param>
 /// <param name="deleteConnections">Flag indicating if the delete should also delete any existing connections with the object.
 /// If <code>deleteConnections=False</code> and any existing connections are present, then this operation will fail.</param>
 /// <param name="options">Request specific api options. These will override the global settings for the app for this request.</param>
 public async static Task DeleteAsync(string type, string id, bool deleteConnections = false, ApiOptions options = null)
 {
     var request = new DeleteObjectRequest()
     {
         Id = id,
         Type = type,
         DeleteConnections = deleteConnections
     };
     ApiOptions.Apply(request, options);
     var response = await request.ExecuteAsync();
     if (response.Status.IsSuccessful == false)
         throw response.Status.ToFault();
 }