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


C# Model.PutObjectRequest类代码示例

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


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

示例1: UploadDataFileAsync

        public async Task UploadDataFileAsync(string data, string storageKeyId, string storageSecret, string region)
        {
            var regionIdentifier = RegionEndpoint.GetBySystemName(region);
            using (var client = new AmazonS3Client(storageKeyId, storageSecret, regionIdentifier))
            {
                try
                {
                    var putRequest1 = new PutObjectRequest
                    {
                        BucketName = AwsBucketName,
                        Key = AwsBucketFileName,
                        ContentBody = data,
                        ContentType = "application/json"
                    };

                    await client.PutObjectAsync(putRequest1);
                }
                catch (AmazonS3Exception amazonS3Exception)
                {
                    if (amazonS3Exception.ErrorCode != null &&
                        (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") || amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                    {
                        throw new SecurityException("Invalid Amazon S3 credentials - data was not uploaded.", amazonS3Exception);
                    }

                    throw new HttpRequestException("Unspecified error attempting to upload data: " + amazonS3Exception.Message, amazonS3Exception);
                }

                var response = await client.GetObjectAsync(AwsBucketName, AwsBucketFileName);
                using (var reader = new StreamReader(response.ResponseStream))
                {
                    Debug.WriteLine(await reader.ReadToEndAsync());
                }
            }
        }
开发者ID:Benrnz,项目名称:BudgetAnalyser,代码行数:35,代码来源:S3MobileDataUploader.cs

示例2: SendImageToS3

        public static Boolean SendImageToS3(String key, Stream imageStream)
        {
            var success = false;

            using (var client = new AmazonS3Client(RegionEndpoint.USWest2))
            {
                try
                {
                    PutObjectRequest request = new PutObjectRequest()
                    {
                        InputStream = imageStream,
                        BucketName = BucketName,
                        Key = key
                    };

                    client.PutObject(request);
                    success = true;
                }

                catch (Exception ex)
                {
                    // swallow everything for now.
                }
            }

            return success;
        }
开发者ID:raynjamin,项目名称:Sitecore-S3-Media,代码行数:27,代码来源:S3Client.cs

示例3: Enviar

        public void Enviar(bool compactar)
        {
            const string mime = "application/octet-stream";
            var nome = _arquivo.Substring(_arquivo.LastIndexOf('\\') + 1) + ".gz";
            var mem = new MemoryStream();

            using (var stream = File.OpenRead(_arquivo))
            using (var gz = new GZipStream(mem, CompressionMode.Compress, true))
            {
                stream.CopyTo(gz);
            }

            var len = mem.Length;
            var req = new PutObjectRequest()
                .WithContentType(mime)
                .WithBucketName(_bucketName)
                .WithKey(nome)
                .WithCannedACL(S3CannedACL.Private)
                .WithAutoCloseStream(true);

            req.InputStream = mem;
            _client.PutObject(req);

            _log.AppendFormat("Envio do arquivo {0} de {1} KB\n",
                              nome,
                              (len / 1024f));
        }
开发者ID:hesenger,项目名称:Backup,代码行数:27,代码来源:EnvioS3.cs

示例4: Write_File_To_S3

        public static bool Write_File_To_S3(String path, String key_name)
        {
            DateTime before = DateTime.Now;
            try
            {
                // simple object put
                PutObjectRequest request = new PutObjectRequest();
                request.WithFilePath(path)
                    .WithBucketName(bucketName)
                    .WithKey(key_name);

                S3Response response = s3_client.PutObject(request);
                response.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception n Write_File_To_S3(String path=" + path + ", String key_name=" + key_name + "). e.Message="+e.Message);
                Console.WriteLine("Write_File_To_S3(String path=" + path + ", String key_name=" + key_name + ") failed!!!");
                return false;
            }
            TimeSpan uploadTime = DateTime.Now - before;
            Console.WriteLine("Uploading " + path + " into S3 Bucket=" + bucketName + " , key=" + key_name + " took " + uploadTime.TotalMilliseconds.ToString() + " milliseconds");

            return true;
        }
开发者ID:tamirez3dco,项目名称:Rendering_Code,代码行数:25,代码来源:S3.cs

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

示例6: Execute

        public override void Execute()
        {
            int timeout = this._config.DefaultTimeout;
            if (this._fileTransporterRequest.Timeout != 0)
                timeout = this._fileTransporterRequest.Timeout;

            PutObjectRequest putRequest = new PutObjectRequest
            {
                BucketName = this._fileTransporterRequest.BucketName,
                Key = this._fileTransporterRequest.Key,
                CannedACL = this._fileTransporterRequest.CannedACL,
                ContentType = this._fileTransporterRequest.ContentType,
                FilePath = this._fileTransporterRequest.FilePath,
                Timeout = timeout,
                StorageClass = this._fileTransporterRequest.StorageClass,
                AutoCloseStream = this._fileTransporterRequest.AutoCloseStream,
                ServerSideEncryptionMethod = this._fileTransporterRequest.ServerSideEncryptionMethod,
            };
            putRequest.PutObjectProgressEvent += new EventHandler<PutObjectProgressArgs>(this.putObjectProgressEventCallback);

            putRequest.InputStream = this._fileTransporterRequest.InputStream;

            if (this._fileTransporterRequest.metadata != null && this._fileTransporterRequest.metadata.Count > 0)
                putRequest.WithMetaData(this._fileTransporterRequest.metadata);
            if (this._fileTransporterRequest.Headers != null && this._fileTransporterRequest.Headers.Count > 0)
                putRequest.AddHeaders(this._fileTransporterRequest.Headers);

            this._s3Client.PutObject(putRequest);
        }
开发者ID:pbutlerm,项目名称:dataservices-sdk-dotnet,代码行数:29,代码来源:SimpleUploadCommand.cs

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

示例8: UploadFile

        private bool UploadFile(string filePath, string s3directory)
        {
            //clean up s3 directory
            s3directory = s3directory.Replace('\\', '/');
            if (s3directory.StartsWith("/")) s3directory = s3directory.Substring(1);
            if (Config.LowerCaseEnforce) s3directory = s3directory.ToLower();

            var key = string.Format("{0}{1}{2}", s3directory, (string.IsNullOrEmpty(s3directory) ? null : "/"), Path.GetFileName(filePath));

            PutObjectRequest request = new PutObjectRequest()
            {
                BucketName = _bucketName,
                Key = key,
                FilePath = filePath,
            };

            PutObjectResponse response = this._client.PutObject(request);

            bool success = (response.HttpStatusCode == System.Net.HttpStatusCode.OK);
            if (success)
                Logger.log.Info("Successfully uploaded file " + filePath + " to " + key);
            else
                Logger.log.Info("Failed to upload file " + filePath);
            return success;
        }
开发者ID:mmendelson222,项目名称:s3-tool,代码行数:25,代码来源:S3Client.cs

示例9: CalculateDiffClocks

        public TimeSpan CalculateDiffClocks()
        {
            try {
                SQ.Repository.File clockFile = new RemoteFile (Constant.CLOCK_TIME);
                PutObjectRequest putObject = new PutObjectRequest ()
                {
                    BucketName = bucketName,
                    Key = clockFile.Name,
                    ContentBody = string.Empty
                };

                DateTime localClock;
                using (S3Response response = Connect ().PutObject (putObject)){
                    localClock = DateTime.Now;
                    response.Dispose ();
                }

                ListObjectsResponse files = Connect ().ListObjects (new ListObjectsRequest ().WithBucketName (bucketName));
                S3Object remotefile = files.S3Objects.Where (o => o.Key == clockFile.Name).FirstOrDefault();
                string sRemoteclock = remotefile.LastModified;

                Delete(clockFile);

                DateTime remoteClock = Convert.ToDateTime (sRemoteclock);

                return localClock.Subtract(remoteClock);

            } catch(Exception e) {
                return new TimeSpan(0);
                Logger.LogInfo ("Connection","Fail to determinate a remote clock: "+e.Message +" \n");
            }
        }
开发者ID:adaptive,项目名称:qloudsync,代码行数:32,代码来源:ConnectionManager.cs

示例10: UploadFile

        public ActionResult UploadFile()
        {
            var file = Request.Files[0];

            if (file != null && file.ContentLength > 0)
            {
                var account = _readOnlyRepository.First<Account>(x => x.Email == User.Identity.Name);

                var client = AWSClientFactory.CreateAmazonS3Client();
                var putObjectRequest = new PutObjectRequest
                    {
                        BucketName = account.BucketName,
                        Key = file.FileName,
                        InputStream = file.InputStream
                    };

                client.PutObject(putObjectRequest);
                //save to database here

                Success("The file " + file.FileName + " was uploaded.");
                return RedirectToAction("Index");
            }
            Error("There was a problem uploading the file.");
            return View("Upload");
        }
开发者ID:kmiloaguilar,项目名称:progra4-minidropbox,代码行数:25,代码来源:DiskController.cs

示例11: ConstructRequest

        private PutObjectRequest ConstructRequest()
        {
            PutObjectRequest putRequest = new PutObjectRequest()
            {
                BucketName = this._fileTransporterRequest.BucketName,
                Key = this._fileTransporterRequest.Key,
                CannedACL = this._fileTransporterRequest.CannedACL,
                ContentType = this._fileTransporterRequest.ContentType,
                StorageClass = this._fileTransporterRequest.StorageClass,
                AutoCloseStream = this._fileTransporterRequest.AutoCloseStream,
                AutoResetStreamPosition = this._fileTransporterRequest.AutoResetStreamPosition,
                ServerSideEncryptionMethod = this._fileTransporterRequest.ServerSideEncryptionMethod,
                Headers = this._fileTransporterRequest.Headers,
                Metadata = this._fileTransporterRequest.Metadata,
#if (BCL && !BCL45)
                Timeout = ClientConfig.GetTimeoutValue(this._config.DefaultTimeout, this._fileTransporterRequest.Timeout)
#endif
            };

#if BCL
            putRequest.FilePath = this._fileTransporterRequest.FilePath;
#elif WIN_RT || WINDOWS_PHONE
            if (this._fileTransporterRequest.IsSetStorageFile())
            {
                putRequest.StorageFile = this._fileTransporterRequest.StorageFile;
            }
#endif
            var progressHandler = new ProgressHandler(this.PutObjectProgressEventCallback);
            putRequest.StreamUploadProgressCallback += progressHandler.OnTransferProgress;

            putRequest.InputStream = this._fileTransporterRequest.InputStream;
            return putRequest;
        }
开发者ID:virajs,项目名称:aws-sdk-net,代码行数:33,代码来源:SimpleUploadCommand.cs

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

示例13: CreateFileFromStream

        public static bool CreateFileFromStream(Stream InputStream, string FileName, string _bucketName = "doc2xml")
        {
            bool _saved=false;
            try
            {

                IAmazonS3 client;
                AmazonS3Config objCon = new AmazonS3Config() ;
                objCon.RegionEndpoint = RegionEndpoint.USEast1;
                using (client = Amazon.AWSClientFactory.CreateAmazonS3Client(_awsAccessKey, _awsSecretKey,objCon))
                {
                    var request = new PutObjectRequest()
                    {
                        BucketName = _bucketName,
                        CannedACL = S3CannedACL.PublicRead,//PERMISSION TO FILE PUBLIC ACCESIBLE
                        Key = string.Format("{0}", FileName),
                        InputStream = InputStream//SEND THE FILE STREAM
                    };

                    client.PutObject(request);
                    _saved = true;
                }
            }
            catch (Exception ex)
            {
                ex.ToString();

            }
            return _saved;
        }
开发者ID:LawrenceAntony,项目名称:Docx2XML,代码行数:30,代码来源:AWSS3.cs

示例14: BucketRegionTestRunner

        public BucketRegionTestRunner(bool useSigV4, bool useSigV4SetExplicitly = false)
        {
            originalUseSignatureVersion4 = AWSConfigsS3.UseSignatureVersion4;
            originalUseSigV4SetExplicitly = GetAWSConfigsS3InternalProperty();
            AWSConfigsS3.UseSignatureVersion4 = useSigV4;
            SetAWSConfigsS3InternalProperty(useSigV4SetExplicitly);

            CreateAndCheckTestBucket();
            if (TestBucketIsReady)
            {
                GetObjectMetadataRequest = new GetObjectMetadataRequest()
                {
                    BucketName = TestBucket.BucketName,
                    Key = TestObjectKey
                };
                PutObjectRequest = new PutObjectRequest()
                {
                    BucketName = TestBucket.BucketName,
                    Key = TestObjectKey,
                    ContentBody = TestContent
                };
                PreSignedUrlRequest = new GetPreSignedUrlRequest
                {
                    BucketName = BucketName,
                    Key = BucketRegionTestRunner.TestObjectKey,
                    Expires = DateTime.Now.AddHours(1)
                };
            }
        }
开发者ID:aws,项目名称:aws-sdk-net,代码行数:29,代码来源:BucketRegionTestRunner.cs

示例15: Execute

        public override void Execute()
        {


            PutObjectRequest putRequest = new PutObjectRequest()
            {
                BucketName = this._fileTransporterRequest.BucketName,
                Key = this._fileTransporterRequest.Key,
                CannedACL = this._fileTransporterRequest.CannedACL,
                ContentType = this._fileTransporterRequest.ContentType,
                FilePath = this._fileTransporterRequest.FilePath,
                StorageClass = this._fileTransporterRequest.StorageClass,
                AutoCloseStream = this._fileTransporterRequest.AutoCloseStream,
                AutoResetStreamPosition = this._fileTransporterRequest.AutoResetStreamPosition,
                ServerSideEncryptionMethod = this._fileTransporterRequest.ServerSideEncryptionMethod,
                Headers = this._fileTransporterRequest.Headers,
                Metadata = this._fileTransporterRequest.Metadata,
#if (BCL && !BCL45)
                Timeout = ClientConfig.GetTimeoutValue(this._config.DefaultTimeout, this._fileTransporterRequest.Timeout)
#endif
            };
            putRequest.StreamUploadProgressCallback += new EventHandler<Runtime.StreamTransferProgressArgs>(this.putObjectProgressEventCallback);

            putRequest.InputStream = this._fileTransporterRequest.InputStream;

            this._s3Client.PutObject(putRequest);
        }
开发者ID:scopely,项目名称:aws-sdk-net,代码行数:27,代码来源:SimpleUploadCommand.cs


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