Exemplo n.º 1
0
 static void DeletingAnObject()
 {
     try
     {
         DeleteObjectRequest request = new DeleteObjectRequest();
         request.WithBucketName(bucketName)
         .WithKey(keyName);
         using (DeleteObjectResponse response = client.DeleteObject(request))
         {
             System.Net.WebHeaderCollection headers = response.Headers;
             foreach (string key in headers.Keys)
             {
                 Console.WriteLine("Response Header: {0}, Value: {1}", key, headers.Get(key));
             }
         }
     }
     catch (AmazonS3Exception amazonS3Exception)
     {
         if (amazonS3Exception.ErrorCode != null &&
             (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") ||
              amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
         {
             Console.WriteLine("Please check the provided AWS Credentials.");
             Console.WriteLine("If you haven't signed up for Amazon S3, please visit http://aws.amazon.com/s3");
         }
         else
         {
             Console.WriteLine("An error occurred with the message '{0}' when deleting an object", amazonS3Exception.Message);
         }
     }
 }
Exemplo n.º 2
0
        public static bool DeleteFile(string FileName, string BucketName)
        {
            bool deleted = false;

            if (FileExist(FileName, BucketName))
            {
                try
                {
                    var s3 = Amazon.AWSClientFactory.CreateAmazonS3Client(ConfigurationManager.AppSettings["AWSAccessKey"], ConfigurationManager.AppSettings["AWSSecretKey"]);
                    DeleteObjectRequest request = new DeleteObjectRequest();
                    request.WithKey(FileName);
                    request.WithBucketName(BucketName);

                    s3.DeleteObject(request);
                    s3.Dispose();

                    deleted = true;
                }
                catch (AmazonS3Exception ex)
                {
                    //Process.CalibrationProcess csProcess = new CalibrationProcess();

                    //emailError("UploadFile", "Error: " + ex.ToString());
                    Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                }
                return(deleted);
            }
            else
            {
                return(deleted);
            }
        }
Exemplo n.º 3
0
        //private void EndAdd(IAsyncResult asyncResult)
        //{
        //    if (!asyncResult.IsCompleted) return;
        //    //_notificationService.PhotoOperation(photo, "Added");
        //    var fileToDelete = asyncResult.AsyncState as string;
        //    if (String.IsNullOrWhiteSpace(fileToDelete)) return;
        //}

        //private void EndDelete(IAsyncResult asyncResult)
        //{
        //    if (!asyncResult.IsCompleted) return;
        //    //_notificationService.PhotoOperation(photo, "Deleted");
        //    var fileToDelete = asyncResult.AsyncState as string;
        //    if (String.IsNullOrWhiteSpace(fileToDelete)) return;
        //}

        private void Delete(string path)
        {
            using (var client = CreateAmazonS3Client()) {
                var request = new DeleteObjectRequest();
                request.WithBucketName(_bucket.BucketName).WithKey(path);
                client.DeleteObject(request);
            }
        }
Exemplo n.º 4
0
        public static void DeletingAnObject(AmazonS3Client client, string bucketName, string keyName)
        {
            DeleteObjectRequest request = new DeleteObjectRequest();

            request.WithBucketName(bucketName)
            .WithKey(keyName);
            S3Response response = client.DeleteObject(request);

            response.Dispose();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Deletes a file
        /// </summary>
        /// <param name="path">Web path to file's folder</param>
        /// <param name="fileName">File name</param>
        public void DeleteFile(string path, string fileName)
        {
            // Prepare delete request
            var request = new DeleteObjectRequest();

            request.WithBucketName(_bucketName)
            .WithKey(GetKey(path, fileName));

            // Delete file
            var response = _client.DeleteObject(request);

            response.Dispose();
        }
Exemplo n.º 6
0
        public JsonResult JSONDeleteAWSFile(string key)
        {
            var request = new DeleteObjectRequest();

            request.WithBucketName(AWSBucket)
            .WithKey(key);

            using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client(AWSAccessKey, AWSSecretKey))
            {
                using (DeleteObjectResponse response = client.DeleteObject(request)) { }
            }

            return(Json(null));
        }
Exemplo n.º 7
0
 public static DeleteObjectResponse delete_S3_Object(this API_AmazonS3 amazonS3, string bucket, string keyToDelete)
 {
     try
     {
         var deleteObjectRequest = new DeleteObjectRequest();
         deleteObjectRequest.WithBucketName(bucket);
         deleteObjectRequest.WithKey(keyToDelete);
         return(amazonS3.S3Client.DeleteObject(deleteObjectRequest));
     }
     catch (Exception ex)
     {
         ex.log("[API_AmazonS3]: in delete_S3_Object()");
     }
     return(null);
 }
Exemplo n.º 8
0
        //removes a file in S3 cloud
        public static void RemoveObjectFromS3(string filePath)
        {
            AmazonS3 client;

            if (CheckS3Credentials())
            {
                NameValueCollection appConfig =
                    ConfigurationManager.AppSettings;

                string accessKeyID       = appConfig["AWSAccessKey"];
                string secretAccessKeyID = appConfig["AWSSecretKey"];

                using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(
                           accessKeyID, secretAccessKeyID, RegionEndpoint.USWest1))
                {
                    try
                    {
                        DeleteObjectRequest request = new DeleteObjectRequest();
                        request.WithBucketName(Constants.AmazonS3BucketName)
                        .WithKey(filePath);

                        S3Response response = client.DeleteObject(request);
                        response.Dispose();
                    }
                    catch (AmazonS3Exception amazonS3Exception)
                    {
                        if (amazonS3Exception.ErrorCode != null &&
                            (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId")
                             ||
                             amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                        {
                            Console.WriteLine("Check the provided AWS Credentials.");
                            Console.WriteLine(
                                "For service sign up go to http://aws.amazon.com/s3");
                        }
                        else
                        {
                            Console.WriteLine(
                                "Error occurred. Message:'{0}' when deleting an object"
                                , amazonS3Exception.Message);
                        }
                    }
                }
            }
        }
Exemplo n.º 9
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));
            }
        }
        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.º 11
0
        /// <summary>
        /// Delete the specified image
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="fileName"></param>
        public override void DeleteImage(string filePath, string key)
        {
            DeleteObjectRequest request = new DeleteObjectRequest();

            request.WithBucketName("images.climbfind.com" + filePath)
            .WithKey(key);

            using (var client = Amazon.AWSClientFactory.CreateAmazonS3Client(Stgs.AWSAccessKey, Stgs.AWSSecretKey, S3Config))
            {
                // simple object put
                using (DeleteObjectResponse response = client.DeleteObject(request))
                {
                    //-- Do a little bit of tracing
                    string headersString        = string.Empty;
                    WebHeaderCollection headers = response.Headers;
                    foreach (string h in headers.Keys)
                    {
                        headersString += string.Format("Response Header: {0}, Value: {1}", h, headers.Get(h));
                    }
                    CfTrace.Information(TraceCode.DeletingImage, headersString);
                }
            }
        }