本文整理汇总了C#中Amazon.S3.Model.GetObjectRequest类的典型用法代码示例。如果您正苦于以下问题:C# GetObjectRequest类的具体用法?C# GetObjectRequest怎么用?C# GetObjectRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GetObjectRequest类属于Amazon.S3.Model命名空间,在下文中一共展示了GetObjectRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteFile
// Delete file from the server
private void DeleteFile(HttpContext context)
{
var _getlen = 10;
var fileName = context.Request["f"];
var fileExt = fileName.Remove(0,fileName.LastIndexOf('.')).ToLower();
var hasThumb = Regex.Match(fileName.ToLower(),AmazonHelper.ImgExtensions()).Success;
var keyName = GetKeyName(context,HttpUtility.UrlDecode(context.Request["f"]));
var client = AmazonHelper.GetS3Client();
var extrequest = new GetObjectRequest()
.WithByteRange(0,_getlen)
.WithKey(keyName)
.WithBucketName(StorageRoot);
var extresponse = client.GetObject(extrequest);
var length = extresponse.ContentLength;
extresponse.Dispose();
if(length == _getlen + 1){
var delrequest = new DeleteObjectRequest()
.WithKey(keyName)
.WithBucketName(StorageRoot);
var delresponse = client.DeleteObject(delrequest);
delresponse.Dispose();
if(hasThumb){
try
{
keyName = keyName.Replace(fileName,"thumbs/" + fileName.Replace(fileExt,".png"));
var thumbcheck = new GetObjectRequest()
.WithByteRange(0,_getlen)
.WithKey(keyName)
.WithBucketName(StorageRoot);
var thumbCheckResponse = client.GetObject(thumbcheck);
length = extresponse.ContentLength;
thumbCheckResponse.Dispose();
if(length == _getlen + 1){
var thumbdelrequest = new DeleteObjectRequest()
.WithKey(keyName)
.WithBucketName(StorageRoot);
var thumbdelresponse = client.DeleteObject(thumbdelrequest);
delresponse.Dispose();
}
}
catch (Exception ex)
{
var messg = ex.Message;
}
}
}
}
示例2: ConvertToGetObjectRequest
protected GetObjectRequest ConvertToGetObjectRequest(BaseDownloadRequest request)
{
GetObjectRequest getRequest = new GetObjectRequest()
{
BucketName = request.BucketName,
Key = request.Key,
VersionId = request.VersionId
};
getRequest.BeforeRequestEvent += this.RequestEventHandler;
if (request.IsSetModifiedSinceDate())
{
getRequest.ModifiedSinceDate = request.ModifiedSinceDate;
}
if (request.IsSetUnmodifiedSinceDate())
{
getRequest.UnmodifiedSinceDate = request.UnmodifiedSinceDate;
}
getRequest.ServerSideEncryptionCustomerMethod = request.ServerSideEncryptionCustomerMethod;
getRequest.ServerSideEncryptionCustomerProvidedKey = request.ServerSideEncryptionCustomerProvidedKey;
getRequest.ServerSideEncryptionCustomerProvidedKeyMD5 = request.ServerSideEncryptionCustomerProvidedKeyMD5;
return getRequest;
}
示例3: GetS3ObjectAsString
public S3ObjectAsString GetS3ObjectAsString(S3KeyBuilder s3Key)
{
var request = new GetObjectRequest
{
BucketName = AppConfigWebValues.Instance.S3BucketName,
Key = s3Key.FullKey
};
var obj = new S3ObjectAsString();
try
{
using (GetObjectResponse response = _client.GetObject(request))
using (Stream responseStream = response.ResponseStream)
using (var reader = new StreamReader(responseStream))
{
obj.Key = s3Key.FullKey;
obj.ContentBody = reader.ReadToEnd();
}
}
catch (AmazonS3Exception s3x)
{
if (s3x.ErrorCode == S3Constants.NoSuchKey)
return null;
throw;
}
return obj;
}
示例4: ResizeImageAndUpload
public static void ResizeImageAndUpload(AmazonS3 anAmazonS3Client, string aBucketName, string aCurrentPhotoName, string aNewImageName, int aSize)
{
GetObjectRequest myGetRequest = new GetObjectRequest().WithBucketName(aBucketName).WithKey(aCurrentPhotoName);
GetObjectResponse myResponse = anAmazonS3Client.GetObject(myGetRequest);
Stream myStream = myResponse.ResponseStream;
ResizeAndUpload(myStream, anAmazonS3Client, aBucketName, aNewImageName, aSize);
}
示例5: ConvertToGetObjectRequest
protected GetObjectRequest ConvertToGetObjectRequest(BaseDownloadRequest request)
{
GetObjectRequest getRequest = new GetObjectRequest()
{
BucketName = request.BucketName,
Key = request.Key,
VersionId = request.VersionId
};
((Amazon.Runtime.Internal.IAmazonWebServiceRequest)getRequest).AddBeforeRequestHandler(this.RequestEventHandler);
if (request.IsSetModifiedSinceDate())
{
getRequest.ModifiedSinceDate = request.ModifiedSinceDate;
}
if (request.IsSetUnmodifiedSinceDate())
{
getRequest.UnmodifiedSinceDate = request.UnmodifiedSinceDate;
}
getRequest.ServerSideEncryptionCustomerMethod = request.ServerSideEncryptionCustomerMethod;
getRequest.ServerSideEncryptionCustomerProvidedKey = request.ServerSideEncryptionCustomerProvidedKey;
getRequest.ServerSideEncryptionCustomerProvidedKeyMD5 = request.ServerSideEncryptionCustomerProvidedKeyMD5;
return getRequest;
}
示例6: ReadString
/// <summary>
/// Reads a string from an S3 bucket
/// </summary>
/// <param name="location">The location of the data you want to read</param>
/// <param name="guid">The guid of the content you're reading</param>
/// <returns>A string interpretation of the data</returns>
public string ReadString(StorageLocations location, string guid)
{
var keyName = string.Format("{0}/{1}.onx", StorageLocationToString(location), guid);
var request = new GetObjectRequest().WithBucketName(Bucket).WithKey(keyName);
return new StreamReader(_client.GetObject(request).ResponseStream, Encoding.ASCII).ReadToEnd();
}
示例7: DownloadToByteArray
public override byte[] DownloadToByteArray(string container, string fileName)
{
client = AWSClientFactory.CreateAmazonS3Client(ExtendedProperties["accessKey"], ExtendedProperties["secretKey"], RegionEndpoint.USEast1);
String S3_KEY = fileName;
GetObjectRequest request = new GetObjectRequest()
{
BucketName = container,
Key = S3_KEY,
};
GetObjectResponse response = client.GetObject(request);
int numBytesToRead = (int)response.ContentLength;
int numBytesRead = 0;
byte[] buffer = new byte[numBytesToRead];
while (numBytesToRead > 0)
{
int n = response.ResponseStream.Read(buffer, numBytesRead, numBytesToRead);
if (n == 0)
break;
numBytesRead += n;
numBytesToRead -= n;
}
return buffer;
}
示例8: GetFileIfChangedSince
public Stream GetFileIfChangedSince(string s3Url, DateTime lastModified, out DateTime newLastModified)
{
S3PathParts path = _pathParser.Parse(s3Url);
var request = new GetObjectRequest
{
BucketName = path.Bucket,
Key = path.Key,
ModifiedSinceDate = lastModified
};
try
{
// Do NOT dispose of the response here because it will dispose of the response stream also
// (and that is ALL it does). It's a little gross, but I'll accept it because the alternative
// is to return a custom Stream that will dispose the response when the Stream itself is
// disposed, which is grosser.
GetObjectResponse response = _s3Client.GetObject(request);
newLastModified = response.LastModified;
return response.ResponseStream;
}
catch (AmazonS3Exception e)
{
if (e.StatusCode == HttpStatusCode.NotModified)
{
newLastModified = default(DateTime);
return null;
}
throw;
}
}
示例9: ViewStats
public ActionResult ViewStats(string id)
{
using (var client = Amazon.AWSClientFactory.CreateAmazonS3Client(AwsAccessKey, AwsSecretAccessKey))
{
var request = new GetObjectRequest();
request.WithBucketName("MyTwitterStats");
request.WithKey(id + ".json.gz");
GetObjectResponse response = null;
try
{
response = client.GetObject(request);
}
catch (AmazonS3Exception)
{
//TODO: Log exception.ErrorCode
return HttpNotFound();
}
using (response)
using (var stream = response.ResponseStream)
using (var zipStream = new GZipStream(stream, CompressionMode.Decompress))
using (var reader = new StreamReader(zipStream))
{
var jsonSerializer = JsonSerializer.Create(new JsonSerializerSettings());
var stats = jsonSerializer.Deserialize<Stats>(new JsonTextReader(reader));
return View(stats);
}
}
}
示例10: ReadByteArray
/// <summary>
/// Reads a byte array from an S3 bucket
/// </summary>
/// <param name="location">The location of the data you want to read</param>
/// <param name="guid">The guid of the content you're reading</param>
/// <returns>A byte array interpretation of the data</returns>
public byte[] ReadByteArray(StorageLocations location, string guid)
{
var keyName = string.Format("{0}/{1}.onx", StorageLocationToString(location), guid);
var request = new GetObjectRequest().WithBucketName(Bucket).WithKey(keyName);
return VariousFunctions.StreamToByteArray(_client.GetObject(request).ResponseStream);
}
示例11: TestAllFilesExistAndModifiedInOutput
public void TestAllFilesExistAndModifiedInOutput()
{
try
{
Init();
ListObjectsRequest inputFileObjects;
String fileKey = null;
inputFileObjects = new ListObjectsRequest
{
BucketName = DataTransformer.InputBucketName
};
ListObjectsResponse listResponse;
do
{
listResponse = DataTransformer.s3ForStudentBuckets.ListObjects(inputFileObjects);
foreach (S3Object obj in listResponse.S3Objects)
{
fileKey = obj.Key;
GetObjectRequest request = new GetObjectRequest()
{
BucketName = DataTransformer.OutputBucketName,
Key = fileKey
};
GetObjectResponse response = DataTransformer.s3ForStudentBuckets.GetObject(request);
StreamReader reader = new StreamReader(response.ResponseStream);
string content = reader.ReadToEnd();
if(!content.Contains(DataTransformer.JsonComment))
{
Assert.Fail("Failure - Input file not transformed; output file does not contain JSON comment. " + fileKey);
}
}
// Set the marker property
inputFileObjects.Marker = listResponse.NextMarker;
} while (listResponse.IsTruncated);
}
catch (AmazonServiceException ase)
{
Console.WriteLine("Error Message: " + ase.Message);
Console.WriteLine("HTTP Status Code: " + ase.StatusCode);
Console.WriteLine("AWS Error Code: " + ase.ErrorCode);
Console.WriteLine("Error Type: " + ase.ErrorType);
Console.WriteLine("Request ID: " + ase.RequestId);
}
catch (AmazonClientException ace)
{
Console.WriteLine("Error Message: " + ace.Message);
}
}
示例12: GetObject
private static void GetObject(AmazonS3 s3Client, string bucket, string key)
{
var getObjectRequest = new GetObjectRequest().WithBucketName(bucket).WithKey(key);
using (var getObjectResponse = s3Client.GetObject(getObjectRequest))
{
var memoryStream = new MemoryStream();
getObjectResponse.ResponseStream.CopyTo(memoryStream);
var content = Encoding.Default.GetString(memoryStream.ToArray());
Console.WriteLine(content);
}
}
示例13: Get
public static void Get(string bucket, string key, string fileName)
{
AmazonS3 s3Client = AWSClientFactory.CreateAmazonS3Client();
FileInfo file = new FileInfo(key);
Console.WriteLine("Download File " + bucket + ":" + key + " to " + fileName);
GetObjectRequest get_req = new GetObjectRequest();
get_req.BucketName = bucket;
get_req.Key = key;
GetObjectResponse get_res = s3Client.GetObject(get_req);
get_res.WriteResponseStreamToFile(fileName);
Console.WriteLine(get_res.Metadata.AllKeys.FirstOrDefault());
}
示例14: PerformGetRequest
void PerformGetRequest(string targetFile, GetObjectRequest request)
{
using (var response = httpRetryService.WithRetry(() => s3.GetObject(request)))
{
using (var stream = response.ResponseStream)
{
using (var outputStream = fileSystem.CreateWriteStream(targetFile))
{
stream.CopyTo(outputStream);
}
}
}
}
示例15: BlobExists
/// <summary>
/// Determines whether a blob item under the specified location exists.
/// </summary>
/// <param name="location">Descriptor of the item on the remote blob storage.</param>
/// <returns>True if the item exists, otherwise - false</returns>
public override bool BlobExists(IBlobContentLocation location)
{
var request = new GetObjectRequest().WithBucketName(this.bucketName).WithKey(location.FilePath);
try
{
var response = transferUtility.S3Client.GetObject(request);
return true;
}
catch (AmazonS3Exception err)
{
}
return false;
}