本文整理汇总了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);
}
示例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();
}
示例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);
}
}
示例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));
}
}
示例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,
})) { }
});
}
}
}
}
}
示例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);
}
}
}
示例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.");
}
}
}
示例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;
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
}
示例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)
{
}
}
}
示例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");
}
示例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;
}
示例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;
}