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


C# AmazonS3.PutObject方法代码示例

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


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

示例1: Main

        public static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();
            log.Info("Initializing and connecting to AWS...");

            s3 = AWSClientFactory.CreateAmazonS3Client(RegionEndpoint.USWest1);
            indexer = new FileIndexer("Files");
            indexer.Index();

            s3indexer = new S3Indexer(Settings.Default.BucketName, Settings.Default.FolderName, "S3Tmp", s3);
            s3indexer.Index();

            log.Info("Comparing local index and remote index.");

            var filesToUpload = (from filePair in indexer.FileIndex where !s3indexer.HashedFiles.ContainsKey(filePair.Key) || !s3indexer.HashedFiles[filePair.Key].SequenceEqual(filePair.Value) select filePair.Key).ToList();
            var filesToDelete = (from filePair in s3indexer.HashedFiles where !indexer.FileIndex.ContainsKey(filePair.Key) select filePair.Key).ToList();

            foreach(var fileDelete in filesToDelete)
            {
                log.Debug("Deleting file "+fileDelete);
                s3.DeleteObject(new DeleteObjectRequest()
                                    {
                                        BucketName = Settings.Default.BucketName,
                                        Key = Settings.Default.FolderName + "/" + fileDelete
                                    });
            }

            foreach(var fileUpload in filesToUpload)
            {
                log.Debug("Uploading file "+fileUpload);
                s3.PutObject(new PutObjectRequest()
                                 {
                                     BucketName = Settings.Default.BucketName,
                                     Key = Settings.Default.FolderName + "/" + fileUpload,
                                     AutoCloseStream = true,
                                     InputStream = new FileStream("Files/" + fileUpload, FileMode.Open)
                                 });
            }

            log.Info("Re-indexing files...");

            using (MemoryStream stream = new MemoryStream())
            {
                Serializer.Serialize(stream, indexer.FileIndex);
                stream.Position = 0;
                s3.PutObject(new PutObjectRequest()
                {
                    BucketName = Settings.Default.BucketName,
                    Key = Settings.Default.FolderName + "/" + "index.mhash",
                    InputStream = stream
                });
            }

            log.Info("Done!");

            Console.Read();
        }
开发者ID:paralin,项目名称:S3FolderSync,代码行数:57,代码来源:Program.cs

示例2: 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

示例3: 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

示例4: 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

示例5: 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

示例6: WalkAndUpload

        public void WalkAndUpload(string path, string bucket, AmazonS3 client)
        {
            foreach (var f in Directory.GetFiles(path))
            {
                var fi = new FileInfo(f);
                if (fi.Name.StartsWith("."))
                {
                    continue;
                } //ignore ".gitignore"

                string fileToPush = f;
                string destinationName =
                    Regex.Split(fileToPush, @"gitCheckout-[\d]*")[1].Replace("\\", "/").TrimStart("/".ToCharArray());

                var poR = new PutObjectRequest()
                    {
                        BucketName = bucket,
                        FilePath = fileToPush,
                        Key = destinationName,
                        Timeout = -1,
                        ReadWriteTimeout = 300000,
                        CannedACL = S3CannedACL.PublicRead
                    };
                var res = client.PutObject(poR);

            }

            foreach (var d in Directory.GetDirectories(path))
            {
                var di = new DirectoryInfo(d);
                if (di.Name.StartsWith("."))
                {
                    continue;
                } //ignore ".git"
                WalkAndUpload(d, bucket, client);
            }
        }
开发者ID:CRuppert,项目名称:s3StaticSiteGitDeployments,代码行数:37,代码来源:Publisher.cs

示例7: AddImageToAmazon

        private bool AddImageToAmazon(Coupon coupon, HttpPostedFile File, string ext)
        {
            string count = "";
            string keyname = "";
            //ext = ".jpg";
            //try
            //{
                string accessKeyID = WebConfigurationManager.AppSettings["AWSAccessKey"];
                string secretAccessKeyID = WebConfigurationManager.AppSettings["AWSSecretKey"];

                AmazonS3Config s3Config = new AmazonS3Config();
                s3Config.UseSecureStringForAwsSecretKey = false;

                client = Amazon.AWSClientFactory.CreateAmazonS3Client(accessKeyID, secretAccessKeyID, s3Config);
                //count += "1";
                ICouponDAO couponDAO = _factoryDAO.GetCouponDAO();
                Byte[] imgByte = new byte[0];
                //count += "2";
                //Create byte Array with file len
                imgByte = new Byte[File.ContentLength];
                //count += "3";
                //force the control to load data in array
                File.InputStream.Read(imgByte, 0, File.ContentLength);
                //count += "4";
                //count += ext;
                //count += _merchantname;
                //count += _couponID.ToString();
                //count += File.FileName;
                //count += File.FileName.Substring(0, File.FileName.IndexOf("."));
                //count += ":";
                //count += string.Format("{0}{1}", _couponID.ToString(), ext);
                keyname = string.Format("{0}/{1}", _merchantname, File.FileName.Replace(File.FileName.Substring(0, File.FileName.IndexOf(".")), string.Format("{0}{1}", _couponID.ToString(), ext)));
                //keyname = string.Format("{0}/{1}", _merchantname, File.FileName.Replace(File.FileName.Substring(0, File.FileName.IndexOf(".")), _couponID.ToString()));
                count += keyname;
                /*try
                {
                    //first try deleting old item if applicable
                    DeleteObjectRequest delete_request = new DeleteObjectRequest();
                    delete_request.WithBucketName("gfck").WithKey(string.Format("coupon/{0}", keyname));
                    S3Response delete_response = client.DeleteObject(delete_request);
                    delete_response.Dispose();
                }
                catch (Exception ex)
                {
                    _log.ErrorFormat("Error trying to delete object from bucket: {0} with exception {1}", keyname, ex.Message);
                }*/
                string BUCKET_NAME = String.Format("gfck/coupon/{0}", _merchantname);
                try
                {
                    //add the bucket just in case not already there.
                    //PutObjectRequest request1 = new PutObjectRequest();
                    PutBucketRequest req = new PutBucketRequest();
                    req.WithBucketName(BUCKET_NAME);
                    //count += "6";
                    //request1.WithBucketName("gfck").WithContentType(File.ContentType).WithCannedACL(S3CannedACL.PublicReadWrite).WithKey(BUCKET_NAME);
                    //S3Response response = client.PutObject(request1);
                    //response.Dispose();
                    client.PutBucket(req);
                }
                catch (Exception ex)
                {
                    _log.DebugFormat("This bucket already exists: {0} with exception {1}", BUCKET_NAME, ex.Message);
                }

                //count += "5";
                PutObjectRequest request = new PutObjectRequest();
                //count += "6";
                request.WithBucketName("gfck").WithContentType(File.ContentType).WithCannedACL(S3CannedACL.PublicRead).WithKey(string.Format("coupon/{0}", keyname)).WithInputStream(File.InputStream);
                count += "here";
                S3Response response = client.PutObject(request);
                count += "7";
                response.Dispose();
                count += "8";
                if (ext == "")
                {
                    coupon.Image = keyname;
                }
                else
                {
                    coupon.BottomAdvertisement = keyname;
                }
                count += "9";

                return couponDAO.UpdateCoupon(coupon);
            /*}
            catch (Exception ex)
            {
                _log.ErrorFormat("Exception Occurred: Exception={0}", ex.Message);
                lblError.Text = String.Format("Error with coupon image. {0} {1} {2}", count, keyName, ex.Message);
                lblError.Visible = true;
                lblAddSuccessfull.Visible = false;
                lblEditSuccessfull.Visible = false;
                return false;
            }*/
        }
开发者ID:jedgoski,项目名称:GFCK,代码行数:95,代码来源:Action.aspx.cs

示例8: putInS3Bucket

        public void putInS3Bucket(resume resume, string txtResults, string[] generatedFiles, string storedFilePath, string generatedFilePath)
        {
            using (client = Amazon.AWSClientFactory.CreateAmazonS3Client("AKIAJ47VSG7WMA62WLCA", "3tqlHujlftpk6j/z5OtDw2eg9N2FJtz1RwL8bEa3"))
            {

                string keyName;
                S3Response response;

                if (resume.hasIMG)
                {
                    var pageNo = 0;
                    var append = false;
                    foreach (string fileName in generatedFiles)
                    {
                        keyName = "img/" + resume.resumeID.ToString();
                        keyName = append ? (keyName + "_" + pageNo.ToString()) : keyName;
                        PutObjectRequest imgRequest = new PutObjectRequest();
                        imgRequest.WithBucketName("intelrecruiter")
                            .WithCannedACL(S3CannedACL.PublicRead)
                            .WithFilePath(fileName)
                            .WithKey(keyName);

                        response = client.PutObject(imgRequest);
                        response.Dispose();
                        append = true;
                        pageNo++;
                    }
                }

                if (resume.hasTXT)
                {
                    keyName = "txt/" + resume.resumeID.ToString();
                    PutObjectRequest txtRequest = new PutObjectRequest();

                    if (resume.hasDOCX)
                    {
                        txtRequest.WithBucketName("intelrecruiter")
                            .WithCannedACL(S3CannedACL.PublicRead)
                            .WithContentBody(txtResults)
                            .WithKey(keyName);
                    }
                    else
                    {
                        txtRequest.WithBucketName("intelrecruiter")
                            .WithCannedACL(S3CannedACL.PublicRead)
                            .WithFilePath(generatedFilePath)
                            .WithKey(keyName);
                    }
                    response = client.PutObject(txtRequest);
                    response.Dispose();
                }

                if (resume.hasPDF)
                {
                    keyName = "pdf/" + resume.resumeID.ToString();
                    PutObjectRequest pdfRequest = new PutObjectRequest();
                    pdfRequest.WithBucketName("intelrecruiter")
                        .WithCannedACL(S3CannedACL.PublicRead)
                        .WithFilePath(storedFilePath)
                        .WithKey(keyName);

                    response = client.PutObject(pdfRequest);
                    response.Dispose();
                }

                if (resume.hasDOCX)
                {
                    keyName = "docx/" + resume.resumeID.ToString();
                    PutObjectRequest imgRequest = new PutObjectRequest();
                    imgRequest.WithBucketName("intelrecruiter")
                        .WithCannedACL(S3CannedACL.PublicRead)
                        .WithFilePath(storedFilePath)
                        .WithKey(keyName);

                    response = client.PutObject(imgRequest);
                    response.Dispose();
                }
            }
        }
开发者ID:nnennaude,项目名称:recruiter-web,代码行数:79,代码来源:ResumeFiles.cs

示例9: BackUpToAmazon

        private void BackUpToAmazon(AmazonS3 client)
        {
            try
            {
                PutObjectRequest request = new PutObjectRequest();
                request.WithBucketName(this.BucketName).WithKey(FileLocations.CONFIG_FILENAME)
                    .WithFilePath(settings.FileLocations.Configuration);

                client.PutObject(request);

                this.ErrorLabel.ForeColor = Color.Black;
                this.ErrorLabel.Text = "The backup was a success!";
            }
            catch (Exception exception)
            {
                this.ErrorLabel.ForeColor = Color.Red;
                this.ErrorLabel.Text = exception.Message;
            }
        }
开发者ID:oo00spy00oo,项目名称:SharedTerminals,代码行数:19,代码来源:AmazonOptionPanel.cs

示例10: GetAll

        public ActionResult GetAll(int[] resumesToDelete)
        {
            string executableDir = Server.MapPath("~/executables");

            resume resume;
            ResumeFiles resumeFileRequest = new ResumeFiles();

            var zipName = User.Identity.Name;
            var fileName = zipName + ".zip";

            string uploadDir = getUploadDir();
            Directory.SetCurrentDirectory(uploadDir);
            foreach (int resumeID in resumesToDelete)
            {

                resume = resumeRepository.GetResume(resumeID);

                resumeFileRequest.getFilefromS3(resume, zipName);

            }

            var command = "\"" + executableDir + "\\7za\" a " + fileName + " " + zipName;
            ExecuteCommandSync(command);

            var fullPath = Path.Combine(uploadDir, fileName);
            var folderPath = Path.Combine(uploadDir, zipName);
            string contentType = "application/zip";

               string keyName = "user_downloads/" + fileName;
               using (client = Amazon.AWSClientFactory.CreateAmazonS3Client("AKIAJ47VSG7WMA62WLCA", "3tqlHujlftpk6j/z5OtDw2eg9N2FJtz1RwL8bEa3"))
               {
               S3Response response;

                PutObjectRequest s3request = new PutObjectRequest();
                s3request.WithBucketName("intelrecruiter")
                    .WithCannedACL(S3CannedACL.PublicRead)
                    .WithFilePath(fullPath)
                    .WithKey(keyName);

                response = client.PutObject(s3request);
                response.Dispose();

               }
               FileInfo newFile = new FileInfo(fullPath);
               newFile.Delete();

               DirectoryInfo dir = new DirectoryInfo(folderPath);
               dir.Delete(true);

               return RedirectToAction("List", new { user_download = keyName });

            //return File(fullPath, contentType, zipName + ".zip");

            /*
            FileInfo newFile = new FileInfo(fullPath);

            string attachment = string.Format("attachment; filename={0}", fileName);
            Response.Clear();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = contentType;
            Response.WriteFile(newFile.FullName);
            Response.Flush();
            newFile.Delete();

            DirectoryInfo dir = new DirectoryInfo(folderPath);
            dir.Delete(true);
            */
            //return RedirectToAction("Index");
        }
开发者ID:nnennaude,项目名称:recruiter-web,代码行数:69,代码来源:ResumesController.cs

示例11: UploadFile

 public static string UploadFile(AmazonS3 client, string filepath)
 {
     //S3_KEY is name of file we want upload
     S3_KEY = System.IO.Path.GetFileName(filepath);
     PutObjectRequest request = new PutObjectRequest();
     request.WithBucketName(BUCKET_NAME);
     request.WithKey(S3_KEY);
     //request.WithInputStream(MemoryStream);
     request.WithFilePath(filepath);
     client.PutObject(request);
     return S3_KEY;
 }
开发者ID:xescrp,项目名称:breinstormin,代码行数:12,代码来源:S3Engine.cs

示例12: PutObject

        private static void PutObject(AmazonS3 s3Client, string bucket, string key)
        {
            var putObjectRequest = new PutObjectRequest();
              putObjectRequest.WithBucketName(bucket)
                      .WithKey(key)
                      .WithContentType("text/plain")
                      .WithContentBody(key);

              var objectResponse = s3Client.PutObject(putObjectRequest);
              objectResponse.Dispose();
        }
开发者ID:nrazon,项目名称:S3Emulator,代码行数:11,代码来源:Program.cs

示例13: saveSession

        private void saveSession(Cookie cookie)
        {
            string cookieName = cookie.Name;
            string cookieValue = cookie.Value;

            using (client = Amazon.AWSClientFactory.CreateAmazonS3Client("AKIAJ47VSG7WMA62WLCA", "3tqlHujlftpk6j/z5OtDw2eg9N2FJtz1RwL8bEa3"))
            {
                PutObjectRequest txtRequest = new PutObjectRequest();

                txtRequest.WithBucketName("intelrecruiter")
                            .WithContentBody(cookieName)
                            .WithKey(nsbeCookieNameKey);

                var response = client.PutObject(txtRequest);
                response.Dispose();

                txtRequest = new PutObjectRequest();

                txtRequest.WithBucketName("intelrecruiter")
                            .WithContentBody(cookieValue)
                            .WithKey(nsbeCookieValueKey);

                response = client.PutObject(txtRequest);
                response.Dispose();

            }

            nsbeCookie = new Cookie(cookieName, cookieValue, "/");
        }
开发者ID:nnennaude,项目名称:recruiter-web,代码行数:29,代码来源:NSBESearch.cs


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