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


C# PutObjectRequest.WithBucketName方法代码示例

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


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

示例1: SaveObjectInAws

        static void SaveObjectInAws(Stream pObject, string keyname)
        {
            try
            {
                using (var client = Amazon.AWSClientFactory.CreateAmazonS3Client())
                {
                    // simple object put
                    PutObjectRequest request = new PutObjectRequest();
                    request.WithBucketName(ConfigurationManager.AppSettings["bucketname"]).WithKey(keyname).WithInputStream(pObject);

                    using (client.PutObject(request)) { }
                }
            }
            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");
                    throw;
                }

                Console.WriteLine("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message);
                throw;
            }
        }
开发者ID:lazarofl,项目名称:Amazon-S3-and-ASP.NET-MVC3---Simple-usage-,代码行数:28,代码来源:HomeController.cs

示例2: Main

        static void Main(string[] args)
        {
            using (AmazonS3 client = Amazon.AWSClientFactory.CreateAmazonS3Client())
            {
                try
                {
                    NameValueCollection appConfig = ConfigurationManager.AppSettings;

                    // get file path
                    string folder = Path.GetFullPath(Environment.CurrentDirectory + "../../../../S3Uploader/");

                    // write uploader form to s3
                    const string uploaderTemplate = "uploader.html";
                    string file = Path.Combine(folder, "Templates/" + uploaderTemplate);

                    var request = new PutObjectRequest();
                    request.WithBucketName(appConfig["AWSBucket"])
                        .WithKey(appConfig["AWSUploaderPath"] + uploaderTemplate)
                        .WithInputStream(File.OpenRead(file));

                    request.CannedACL = S3CannedACL.PublicRead;
                    request.StorageClass = S3StorageClass.ReducedRedundancy;

                    S3Response response = client.PutObject(request);
                    response.Dispose();

                    // write js to s3
                    var jsFileNames = new[] { "jquery.fileupload.js", "jquery.iframe-transport.js", "s3_uploader.js" };
                    foreach (var jsFileName in jsFileNames)
                    {
                        file = Path.Combine(folder, "Scripts/s3_uploader/" + jsFileName);
                        request = new PutObjectRequest();

                        request.WithBucketName(appConfig["AWSBucket"])
                            .WithKey(appConfig["AWSUploaderPath"] + "js/" + jsFileName)
                            .WithInputStream(File.OpenRead(file));

                        request.CannedACL = S3CannedACL.PublicRead;
                        request.StorageClass = S3StorageClass.ReducedRedundancy;

                        response = client.PutObject(request);
                        response.Dispose();
                    }
                }
                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 writing an object", amazonS3Exception.Message);
                    }
                }
            }
        }
开发者ID:barneybbq,项目名称:S3Uploader,代码行数:60,代码来源:Program.cs

示例3: SaveImage

 /// <summary>
 /// Saves image to images.climbfind.com
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="filePath"></param>
 /// <param name="key"></param>
 public override void SaveImage(Stream stream, string filePath, string key)
 {
     try
     {
         using (var client = Amazon.AWSClientFactory.CreateAmazonS3Client(Stgs.AWSAccessKey, Stgs.AWSSecretKey, S3Config))
         {
             // simple object put
             PutObjectRequest request = new PutObjectRequest();
             request.WithBucketName("images.climbfind.com" + filePath);
             request.WithInputStream(stream);
             request.ContentType = "image/jpeg";
             request.Key = key;
             request.WithCannedACL(S3CannedACL.PublicRead);
             client.PutObject(request);
         }
     }
     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 writing an object", amazonS3Exception.Message);
         }
     }
 }
开发者ID:jkresner,项目名称:Climbfind_v4_2011,代码行数:37,代码来源:AwsS3ImagePersister.cs

示例4: PutImage

        public string PutImage(IWebCamImage webCamImage, out string key)
        {
            if (webCamImage.Data != null) // accept the file
            {
                // AWS credentials.
                const string accessKey = "{sensitive}";
                const string secretKey = "{sensitive}";

                // Setup the filename.
                string fileName = Guid.NewGuid() + ".jpg";
                string url = null;

                // Drop the image.
                AmazonS3 client;
                using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKey, secretKey))
                {
                    var request = new PutObjectRequest();
                    var config = ConfigurationManager.AppSettings;
                    request.WithBucketName(config["awsBucket"])
                        .WithCannedACL(S3CannedACL.PublicRead)
                        .WithKey(fileName).WithInputStream(new MemoryStream(webCamImage.Data));
                    S3Response response = client.PutObject(request);
                    url = config["awsRootUrl"] + "/" + config["awsBucket"] + "/" + fileName;
                }

                // Return our result.
                key = fileName;
                return url;
            }
            key = null;
            return null;
        }
开发者ID:bernardoleary,项目名称:MyBigBro,代码行数:32,代码来源:AwsStorageServiceAgent.cs

示例5: CreateNewFolder

 public static string CreateNewFolder(AmazonS3 client, string foldername)
 {
     String S3_KEY = foldername;
     PutObjectRequest request = new PutObjectRequest();
     request.WithBucketName(BUCKET_NAME);
     request.WithKey(S3_KEY);
     request.WithContentBody("");
     client.PutObject(request);
     return S3_KEY;
 }
开发者ID:xescrp,项目名称:breinstormin,代码行数:10,代码来源:S3Engine.cs

示例6: PutScreenshot

        public void PutScreenshot(Amazon.S3.AmazonS3 amazonS3Client, string bucketName, string path, Stream stream)
        {
            var putObjectRequest = new PutObjectRequest();

            putObjectRequest.WithInputStream(stream);
            putObjectRequest.WithBucketName(bucketName);
            putObjectRequest.WithKey(path);

            amazonS3Client.PutObject(putObjectRequest);
        }
开发者ID:meze,项目名称:betteamsbattle,代码行数:10,代码来源:ScreenshotAmazonS3Putter.cs

示例7: CreateObject

        public void CreateObject(string bucketName, Stream fileStream)
        {
            PutObjectRequest request = new PutObjectRequest();
            request.WithBucketName(bucketName);
            request.WithInputStream(fileStream);
            request.CannedACL = S3CannedACL.PublicRead;

            S3Response response = _client.PutObject(request);
            response.Dispose();
        }
开发者ID:Jeavon,项目名称:Cloud-Proivders-for-Universal-Media-Picker,代码行数:10,代码来源:StorageFactory.cs

示例8: CreateNewFileInFolder

 public static string CreateNewFileInFolder(AmazonS3 client, string foldername, string filepath)
 {
     String S3_KEY = foldername + "/" + System.IO.Path.GetFileName(filepath);
     PutObjectRequest request = new PutObjectRequest();
     request.WithBucketName(BUCKET_NAME);
     request.WithKey(S3_KEY);
     request.WithFilePath(filepath);
     //request.WithContentBody("This is body of S3 object.");
     client.PutObject(request);
     return S3_KEY;
 }
开发者ID:xescrp,项目名称:breinstormin,代码行数:11,代码来源:S3Engine.cs

示例9: SaveFile

 /// <summary>
 /// The save file.
 /// </summary>
 /// <param name="awsAccessKey">
 /// The AWS access key.
 /// </param>
 /// <param name="awsSecretKey">
 /// The AWS secret key.
 /// </param>
 /// <param name="bucket">
 /// The bucket.
 /// </param>
 /// <param name="path">
 /// The path.
 /// </param>
 /// <param name="fileStream">
 /// The file stream.
 /// </param>
 public static void SaveFile(string awsAccessKey, string awsSecretKey, string bucket, string path, Stream fileStream)
 {
     using (var amazonClient = AWSClientFactory.CreateAmazonS3Client(awsAccessKey, awsSecretKey))
     {
         var createFileRequest = new PutObjectRequest
                                     {
                                         CannedACL = S3CannedACL.PublicRead,
                                         Timeout = int.MaxValue
                                     };
         createFileRequest.WithKey(path);
         createFileRequest.WithBucketName(bucket);
         createFileRequest.WithInputStream(fileStream);
         amazonClient.PutObject(createFileRequest);
     }
 }
开发者ID:Naviam,项目名称:Shop-Any-Ware,代码行数:33,代码来源:AmazonS3Helper.cs

示例10: InsertObject

        public string InsertObject(Stream stream, string keyName)
        {
            var putRequest = new PutObjectRequest();
            putRequest
            .WithBucketName(BucketName)
            .WithKey(keyName)
            .WithCannedACL(S3CannedACL.PublicRead)
            .WithInputStream(stream);

            using (AmazonS3 client = AWSClientFactory.CreateAmazonS3Client(AccessKeyId, SecretAccessKeyId))
            {
                S3Response putResponse = client.PutObject(putRequest);

                return string.Format("http://s3.amazonaws.com/{0}/{1}", BucketName, keyName);
            }
        }
开发者ID:ahmetoz,项目名称:Photopia,代码行数:16,代码来源:AmazonS3Service.cs

示例11: WriteObjectRequest

        public static void WriteObjectRequest(string bucketName, string fileName, Stream fileContent, AmazonS3Client s3Client)
        {
            if (String.IsNullOrEmpty(fileName))
                {
                    return;
                }

                PutObjectRequest putObjectRequest = new PutObjectRequest();

                putObjectRequest.WithBucketName(bucketName)
                    .WithKey(fileName)
                    .WithStorageClass(S3StorageClass.Standard)
                    .WithCannedACL(S3CannedACL.PublicRead)
                    .WithInputStream(fileContent);

                S3Response response = s3Client.PutObject(putObjectRequest);
                response.Dispose();
        }
开发者ID:dbows,项目名称:MVCAssetManager,代码行数:18,代码来源:Helpers.cs

示例12: UploadFileToS3Object

         public bool UploadFileToS3Object(string s3ObjectName, string filePath)
         {

             try
             {
                 PutObjectRequest request = new PutObjectRequest();
                 request.WithBucketName(bucketName);
                 request.WithKey(s3ObjectName);
                 request.WithFilePath(filePath);//request.WithContentBody
                 amazonS3Client.PutObject(request);
                 return true;
             }
             catch (Exception e)
             {
                 structuredLog("E", "Exception in UploadFileToS3Object: "+e);
                 return false;
             }

         }
开发者ID:donnaknew,项目名称:programmingProject,代码行数:19,代码来源:AmazonS3Helper.cs

示例13: AddEntry

        public StorageEntry AddEntry(StorageEntry entry)
        {
            // 本体作成
            using (var stream = new MemoryStream(entry.Contents))
            {
                var request = new PutObjectRequest { InputStream = stream };
                request.WithBucketName(BucketName)
                       .WithKey(entry.Name)
                       .WithContentType(entry.ContentType);

                using (var s3 = GetAmazonS3())
                {
                    var response = s3.PutObject(request);
                    response.Dispose();
                }
            }

            return entry;
        }
开发者ID:takepara,项目名称:MvcPhotos,代码行数:19,代码来源:AwsS3StorageProvider.cs

示例14: UploadEvents

        private void UploadEvents(LoggingEvent[] events, AmazonS3 client)
        {
            var key = Filename(Guid.NewGuid().ToString());

            var content = new StringBuilder(events.Count());
            Array.ForEach(events, logEvent =>
                {
                    using (var writer = new StringWriter())
                    {
                        Layout.Format(writer, logEvent);
                        content.AppendLine(writer.ToString());
                    }
                });

            var request = new PutObjectRequest();
            request.WithBucketName(_bucketName);
            request.WithKey(key);
            request.WithContentBody(content.ToString());
            client.PutObject(request);
        }
开发者ID:mstueck,项目名称:log4net.aws,代码行数:20,代码来源:S3Appender.cs

示例15: ResizeAndUpload

        private static void ResizeAndUpload(Stream aStream, AmazonS3 anS3Client, string aBucketName, string aNewImageName, int aSize)
        {
            Image myOriginal = Image.FromStream(aStream);
            Image myActual = ScaleBySize(myOriginal, aSize);

            MemoryStream myMemoryStream = imageToMemoryStream(myActual);

            PutObjectRequest myRequest = new PutObjectRequest();

            myRequest.WithBucketName(aBucketName)
                .WithCannedACL(S3CannedACL.PublicRead)
                .WithKey(aNewImageName)
                .InputStream = myMemoryStream;

            S3Response myResponse = anS3Client.PutObject(myRequest);

            myActual.Dispose();
            myMemoryStream.Dispose();
            myOriginal.Dispose();
        }
开发者ID:henryksarat,项目名称:Have-A-Voice,代码行数:20,代码来源:AWSPhotoHelper.cs


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