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


C# Model.GetObjectRequest类代码示例

本文整理汇总了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;
                        }
                    }

                }
        }
开发者ID:dbows,项目名称:MVCAssetManager,代码行数:51,代码来源:AmazonTransferHandler.ashx.cs

示例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;
        }
开发者ID:rossmas,项目名称:aws-sdk-net,代码行数:25,代码来源:BaseCommand.cs

示例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;
        }
开发者ID:sgh1986915,项目名称:.net-braintree-spa,代码行数:29,代码来源:S3Dal.cs

示例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);
 }
开发者ID:henryksarat,项目名称:Have-A-Voice,代码行数:7,代码来源:AWSPhotoHelper.cs

示例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;
        }
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:25,代码来源:BaseCommand.cs

示例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();
        }
开发者ID:0xdeafcafe,项目名称:Onyx,代码行数:13,代码来源:S3Storage.cs

示例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;
        }
开发者ID:devaccelerate,项目名称:adapters-aws,代码行数:26,代码来源:AWSFileStorageManager.cs

示例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;
            }
        }
开发者ID:nelsonwellswku,项目名称:stack-it-net,代码行数:30,代码来源:StorageService.cs

示例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);
                }
            }
        }
开发者ID:huseyint,项目名称:MyTwitterStats,代码行数:32,代码来源:HomeController.cs

示例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);
        }
开发者ID:0xdeafcafe,项目名称:Onyx,代码行数:13,代码来源:S3Storage.cs

示例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);
            }
        }
开发者ID:honux77,项目名称:aws-training-demo,代码行数:56,代码来源:DataTransformerTests.cs

示例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);
       }
 }
开发者ID:nrazon,项目名称:S3Emulator,代码行数:11,代码来源:Program.cs

示例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());
 }
开发者ID:rs-services,项目名称:RightGridWindowsImplementation,代码行数:12,代码来源:Storage.cs

示例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);
             }
         }
     }
 }
开发者ID:erikols,项目名称:nget,代码行数:13,代码来源:S3FetchClient.cs

示例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;
        }
开发者ID:raydowe,项目名称:amazon-s3-provider,代码行数:19,代码来源:AmazonBlobStorageProvider.cs


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