当前位置: 首页>>代码示例>>C#>>正文


C# AmazonS3Client.DeleteObject方法代码示例

本文整理汇总了C#中Amazon.S3.AmazonS3Client.DeleteObject方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonS3Client.DeleteObject方法的具体用法?C# AmazonS3Client.DeleteObject怎么用?C# AmazonS3Client.DeleteObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amazon.S3.AmazonS3Client的用法示例。


在下文中一共展示了AmazonS3Client.DeleteObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DeleteFile

 public void DeleteFile(String filename)
 {
     String key = filename;
     var amazonClient = new AmazonS3Client(_keyPublic, _keySecret);
     var deleteObjectRequest = new DeleteObjectRequest { BucketName = _bucket, Key = key };
     var response = amazonClient.DeleteObject(deleteObjectRequest);
 }
开发者ID:Rychard,项目名称:SqlServerBackup,代码行数:7,代码来源:AmazonS3Helper.cs

示例2: DeletingAnObject

 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();
 }
开发者ID:dbows,项目名称:MVCAssetManager,代码行数:8,代码来源:Helpers.cs

示例3: DeleteFromBucket

        public static void DeleteFromBucket(string bucketName, string key)
        {
            using (var client = new AmazonS3Client(Settings.AccessKey, Settings.Secret))
            {
                var request = new DeleteObjectRequest()
                {
                    BucketName = bucketName,
                    Key = key
                };

                client.DeleteObject(request);
            }
        }
开发者ID:korz,项目名称:IntroductionToAmazonAws,代码行数:13,代码来源:Repository.cs

示例4: S3DeleteItem

        public void S3DeleteItem(string bucketName, string keyName)
        {
            //ref: http://docs.aws.amazon.com/AmazonS3/latest/dev/DeletingOneObjectUsingNetSDK.html

            using (var client = new AmazonS3Client(this.AcesssKey, this.SecretKey, this.Region))
            {
                DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest
                {
                    BucketName = bucketName,
                    Key = keyName
                };

                client.DeleteObject(deleteObjectRequest);
                System.Diagnostics.Debug.WriteLine(string.Format("AwsS3 -- Deleted {0}", keyName));
            }
        }
开发者ID:educoutinho,项目名称:AmazonAwsS3Test,代码行数:16,代码来源:AwsClient.cs

示例5: SoftDeleteFolders

        public static void SoftDeleteFolders(ControllerConfiguration context, IEnumerable<string> folders)
        {
            if (context == null)
                throw new ArgumentNullException("context", "Context cannot be null.");
            if (folders == null)
                throw new ArgumentNullException("folders", "Folders cannot be null.");

            using (var client = new AmazonS3Client(context.AwsAccessKeyId, context.AwsSecretAccessKey))
            {
                foreach (var folder in folders)
                {
                    int maxResults = 100;
                    int lastCount = maxResults;
                    while (maxResults == lastCount)
                    {
                        using (var listResponse = client.ListObjects(new ListObjectsRequest()
                        {
                            BucketName = context.BucketName,
                            Prefix = folder,
                        }))
                        {
                            lastCount = listResponse.S3Objects.Count;

                            Parallel.ForEach(listResponse.S3Objects, folderObject =>
                                {
                                    using (var copyResponse = client.CopyObject(new CopyObjectRequest()
                                    {
                                        SourceBucket = context.BucketName,
                                        DestinationBucket = context.BucketName,
                                        SourceKey = folderObject.Key,
                                        DestinationKey = ".recycled/" + folderObject.Key,
                                    })) { }
                                });

                            Parallel.ForEach(listResponse.S3Objects, folderObject =>
                                {
                                    using (var deleteReponse = client.DeleteObject(new DeleteObjectRequest()
                                    {
                                        BucketName = context.BucketName,
                                        Key = folderObject.Key,
                                    })) { }
                                });
                        }
                    }
                }
            }
        }
开发者ID:danielrbradley,项目名称:Plywood,代码行数:47,代码来源:AwsHelpers.cs

示例6: DeleteAllBucketItems

        public static void DeleteAllBucketItems(string bucketName)
        {
            using (var client = new AmazonS3Client(Settings.AccessKey, Settings.Secret))
            {
                var request = new ListObjectsRequest
                {
                    BucketName = bucketName
                };

                var response = client.ListObjects(request);

                foreach (var entry in response.S3Objects)
                {
                    client.DeleteObject(bucketName, entry.Key);
                }
            }
        }
开发者ID:korz,项目名称:IntroductionToAmazonAws,代码行数:17,代码来源:Repository.cs

示例7: DeleteFile

        public static void DeleteFile(string key)
        {
            var s3Config = new AmazonS3Config() { ServiceURL = "http://" + _s3_bucket_region };
            using (var cli = new AmazonS3Client(
                _s3_access_key,
                _s3_secret_access_key,
                s3Config))
            {
                DeleteObjectRequest req = new DeleteObjectRequest()
                {
                    BucketName = _s3_bucket_name,
                    Key = key
                };

                var response = cli.DeleteObject(req);
                if(response.HttpStatusCode != System.Net.HttpStatusCode.NoContent)
                {
                    throw new Exception("s3: delete file failed.");
                }
            }
        }
开发者ID:teo-mateo,项目名称:sdc,代码行数:21,代码来源:S3.cs

示例8: DeleteObject

        /// <summary>AWS S3 단일 객체 삭제</summary>
        public bool DeleteObject(string pKey)
        {
            try
            {
                using (AmazonS3Client client = new AmazonS3Client())
                {
                    DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest
                    {
                        BucketName = strAwsBucketName,
                        Key = pKey
                    };

                    DeleteObjectResponse response = client.DeleteObject(deleteObjectRequest);

                    return true;
                }
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                throw amazonS3Exception;
            }
        }
开发者ID:chae87,项目名称:First,代码行数:23,代码来源:AwsCmm.cs

示例9: EditFile

        private void EditFile(HttpChallenge httpChallenge, bool delete)
        {
            var filePath = httpChallenge.FilePath;

            // 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);

            using (var s3 = new Amazon.S3.AmazonS3Client(
                    CommonParams.ResolveCredentials(),
                    CommonParams.RegionEndpoint))
            {
                if (delete)
                {
                    var s3Requ = new Amazon.S3.Model.DeleteObjectRequest
                    {
                        BucketName = BucketName,
                        Key = filePath,
                    };
                    var s3Resp = s3.DeleteObject(s3Requ);
                }
                else
                {
                    var s3Requ = new Amazon.S3.Model.PutObjectRequest
                    {
                        BucketName = BucketName,
                        Key = filePath,
                        ContentBody = httpChallenge.FileContent,
                        ContentType = ContentType,
                        CannedACL = S3CannedAcl,
                    };
                    var s3Resp = s3.PutObject(s3Requ);
                }
            }
        }
开发者ID:bseddon,项目名称:ACMESharp,代码行数:36,代码来源:AwsS3ChallengeHandler.cs

示例10: DeleteFile

 /// <summary>
 /// delete the filr from s3
 /// </summary>
 /// <param name="PathName"></param>
 /// <param name="FileName"></param>
 /// <returns></returns>
 public bool DeleteFile(string PathName, string FileName)
 {
     try
     {
         //amazon client
         using (var client = new AmazonS3Client())
         {
             //delete request
             using (var response = client.DeleteObject(new DeleteObjectRequest()
                 .WithBucketName(PathName)
                 .WithKey(FileName)))
             {
                 return true;
             }
         }
     }
     catch (Exception ex)
     {
         Trace.WriteLine(ex.ToString());
     }
     return false;
 }
开发者ID:yonglehou,项目名称:Bermuda,代码行数:28,代码来源:StorageAmazon.cs

示例11: MoveFile

        public bool MoveFile(string sourcePath, string sourceBucket, string destinationPath, string destinationBucket)
        {
            try
            {
                var request = new CopyObjectRequest
                {
                    DestinationBucket = destinationBucket,
                    DestinationKey = destinationPath,
                    SourceKey = sourcePath,
                    SourceBucket = sourceBucket
                };

                using (var s3 = new AmazonS3Client(_connectionInfo.AccessKey, _connectionInfo.SecretKey,
                        new AmazonS3Config {ServiceURL = "http://s3.amazonaws.com"}))
                {
                    var response = s3.CopyObject(request);
                    if (response.HttpStatusCode == HttpStatusCode.OK)
                    {
                        s3.DeleteObject(new DeleteObjectRequest() {BucketName = sourceBucket, Key = sourcePath});
                    }
                }

                return true;
            }
            catch (Exception ex)
            {
                Log.Error("Error Moving file", ex);
                return false;
            }
        }
开发者ID:KyleGobel,项目名称:Chronos,代码行数:30,代码来源:S3.cs

示例12: ReplaceAdImages

        public void ReplaceAdImages(ref Ad ad, FileName[] filenames)
        {
            string newFileName = "";
            int count = 1;
            var id = ad.Id;
            var imaa = db.AdImages.Where(x => x.adId.Equals(id)).Count();
            count = imaa + 1;
            for (int i = 1; i < filenames.Length; i++)
            {
                 IAmazonS3 client;
                 try
                 {
                     using (client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1))
                     {
                         GetObjectRequest request = new GetObjectRequest
                         {
                             BucketName = _bucketName,
                             Key = _folderName + filenames[i].fileName
                         };
                         using (GetObjectResponse response = client.GetObject(request))
                         {
                             string filename = filenames[i].fileName;
                             if (!System.IO.File.Exists(filename))
                             {
                                 string extension = System.IO.Path.GetExtension(filenames[i].fileName);
                                 newFileName = ad.Id.ToString() + "_" + count + extension;

                                 client = new AmazonS3Client(Amazon.RegionEndpoint.USEast1);

                                 CopyObjectRequest request1 = new CopyObjectRequest()
                                 {
                                     SourceBucket = _bucketName,
                                     SourceKey = _folderName + filename,
                                     DestinationBucket = _bucketName,
                                     CannedACL = S3CannedACL.PublicRead,//PERMISSION TO FILE PUBLIC ACCESIBLE
                                     DestinationKey = _folderName + newFileName
                                 };
                                 CopyObjectResponse response1 = client.CopyObject(request1);

                                 AdImage image = new AdImage();
                                 image.imageExtension = extension;
                                 image.adId = ad.Id;
                                 db.AdImages.Add(image);
                                 db.SaveChanges();
                                 count++;



                                 DeleteObjectRequest deleteObjectRequest =
                                 new DeleteObjectRequest
                                 {
                                     BucketName = _bucketName,
                                     Key = _folderName + filenames[i].fileName
                                 };
                                 AmazonS3Config config = new AmazonS3Config();
                                 config.ServiceURL = "https://s3.amazonaws.com/";
                                 using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(
                                      _awsAccessKey, _awsSecretKey, config))
                                 {
                                     client.DeleteObject(deleteObjectRequest);
                                 }
                             }
                         }
                     }
                 }
                 catch (Exception e)
                 {

                 }
            }
        }
开发者ID:mubasharali,项目名称:myfiles3,代码行数:71,代码来源:ElectronicsController.cs

示例13: DownloadFiles

        public static void DownloadFiles(string accessKey, string secretKey, string bucketName, string s3FolderName, string saveFolder, bool removeFromS3AfterDownload, Action<GetObjectResponse> onFileDownload = null, Action<DeleteObjectResponse> onFileDelete = null)
        {
            Log.DebugFormat("Starting download of files like '{0}' to '{1}'", bucketName + "/" + s3FolderName, saveFolder);
            if (!Directory.Exists(saveFolder))
            {
                Log.ErrorFormat("Couldn't find folder {0}", saveFolder);
                throw new ArgumentException(string.Format("Could not find folder {0}", saveFolder));
            }

            using (var client = new AmazonS3Client(accessKey, secretKey,
                new AmazonS3Config { ServiceURL = "http://s3.amazonaws.com" }))
            {
                var marker = default(string);
                do
                {
                    var listResponse = ListFiles(accessKey, secretKey, bucketName, s3FolderName, marker);
                    foreach (var f in listResponse.S3Objects.Select(x => x.Key))
                    {
                        var req = new GetObjectRequest
                        {
                            BucketName = bucketName,
                            Key = f
                        };

                        var match = Regex.Match(f, FilepathPattern);

                        var filename = match.Groups["filename_without_extension"].Value;
                        var extension = match.Groups["extension"].Value;
                        var savePath = Path.Combine(saveFolder, filename + "." + extension);
                        var transferPath = savePath + ".tran";
                        Log.DebugFormat("Downloading '{0}' to '{1}'", bucketName + "/" + f, transferPath);
                        var res = client.GetObject(req);

                        if (onFileDownload != null)
                        {
                            Log.Debug("Running onFileDownload filter");
                            onFileDownload(res);
                        }

                        res.WriteResponseStreamToFile(transferPath, false);

                        if (removeFromS3AfterDownload)
                        {
                            var deleteRequest = new DeleteObjectRequest
                            {
                                BucketName = bucketName,
                                Key = f
                            };
                            Log.DebugFormat("Deleting '{0}' from S3", bucketName + "/" + f);
                            var deleteResponse = client.DeleteObject(deleteRequest);
                            if (onFileDelete != null)
                            {
                                Log.Debug("Running onFileDelete filter");
                                onFileDelete(deleteResponse);
                            }
                        }

                        //try to move the file to it's original save spot
                        Log.DebugFormat("Moving file '{0}' to '{1}'", transferPath, savePath);

                        for (var retryCount = 0; retryCount < 3; retryCount++)
                        {
                            try
                            {
                                File.Move(transferPath, savePath);
                                break;
                            }
                            catch (Exception ex)
                            {
                                if (retryCount == 2)
                                {
                                    Log.Error("Failed to move file.  Exceeded retry count", ex);
                                    throw;
                                }

                                Log.ErrorFormat("Failed to move file from '{0}', to '{1}'.  Retry: {2}",
                                    transferPath, savePath, retryCount);

                                Thread.Sleep(1000);
                            }
                        }
                    }
                    marker = listResponse.IsTruncated ? listResponse.NextMarker : default(string);
                } while (marker != default(string));
            }
            Log.Debug("Finished downloading files from s3");
        }
开发者ID:BilliamBrown,项目名称:Chronos,代码行数:87,代码来源:S3.cs

示例14: deleteFile

        public bool deleteFile(string keyName, string bucketName)
        {

            try
            {
                IAmazonS3 client;
                client = new AmazonS3Client(Amazon.RegionEndpoint.USWest2);

                DeleteObjectRequest deleteObjectRequest =
                    new DeleteObjectRequest
                    {
                        BucketName = bucketName,
                        Key = keyName
                    };

                using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(
                     "AKIAIM2K2FSR2DC6KMSA", "yZ2+Mzs8w1iYGPplXNkLfWtOqif9Rad5wjGu3/zn", Amazon.RegionEndpoint.USWest2))
                {
                    var response = client.DeleteObject(deleteObjectRequest);

                }
            }
            catch (Exception)
            {

                return false;
            }
            return true;
        }
开发者ID:rungwe,项目名称:Edubran-Web-Api,代码行数:29,代码来源:UploadsController.cs

示例15: ReplaceObject

        public static String ReplaceObject(HttpPostedFileBase file, String name)
        {
            String filename = name + file.FileName;
            String url = server + bucket + "/" + filename; ;

            using (IAmazonS3 client = new AmazonS3Client(Amazon.RegionEndpoint.EUCentral1))
            {
                //check if file exists and if so deletes it
                var s3FileInfo = new Amazon.S3.IO.S3FileInfo(client, bucket, filename);
                if (s3FileInfo.Exists)
                {
                    DeleteObjectRequest drequest = new DeleteObjectRequest();
                    drequest.BucketName = bucket;
                    drequest.Key = filename;
                    client.DeleteObject(drequest);
                }

                //update the new file
                int size = file.ContentLength;
                PutObjectRequest request = new PutObjectRequest();
                request.CannedACL = S3CannedACL.PublicRead;
                request.BucketName = bucket;
                request.ContentType = file.ContentType;
                request.Key = filename;
                request.InputStream = file.InputStream;
                client.PutObject(request);

                //update traffic
                PictogramsDb.UpdateTraffic(name, size);

            }

            return url;
        }
开发者ID:GSLourenco,项目名称:MyLastVersion,代码行数:34,代码来源:PictoUploader.cs


注:本文中的Amazon.S3.AmazonS3Client.DeleteObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。