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


C# PutObjectRequest.WithInputStream方法代码示例

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


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

示例1: PutRequest

        public string PutRequest(string key, Stream data, string contentType)
        {
            key = key.Replace('\\', '/');

            var putRequest = new PutObjectRequest()
                .WithBucketName(_configuration.BucketName)
                .WithCannedACL(S3CannedACL.PublicRead)
                .WithContentType(contentType)
                .WithKey(key)
                .WithMetaData("Content-Length", data.Length.ToString(CultureInfo.InvariantCulture))
                .WithStorageClass(S3StorageClass.Standard);

            putRequest.WithInputStream(data);

            _client.PutObject(putRequest);

            return string.Concat(_baseStorageEndpoint, key);
        }
开发者ID:JoshuaKaminsky,项目名称:ContentStorage,代码行数:18,代码来源:AmazonS3Client.cs

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

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

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

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

示例6: Add

        protected void Add(string bucketName, Guid id, object newItem)
        {
            string serializedUser = JsonConvert.SerializeObject(newItem);
            byte[] byteStream = Encoding.UTF8.GetBytes(serializedUser);

            var metadata = new NameValueCollection();
            metadata.Add(IdKey, id.ToString());
            metadata.Add(SizeKey, byteStream.Length.ToString());
            metadata.Add(CreationTimeKey, DateTime.UtcNow.ToString());
            metadata.Add(LastWriteTimeKey, DateTime.UtcNow.ToString());

            var stream = new MemoryStream();
            stream.Write(byteStream, 0, byteStream.Length);

            var req = new PutObjectRequest();
            req.WithInputStream(stream);

            using (AmazonS3Client client = SetupClient())
            {
                client.PutObject(req.WithBucketName(bucketName).WithKey(id.ToString()).WithMetaData(metadata));
            }
        }
开发者ID:pitlabcloud,项目名称:activity-cloud,代码行数:22,代码来源:BaseStorage.cs

示例7: WriteFile

    public void WriteFile(string virtualPath, Stream inputStream) {
      var request = new PutObjectRequest()
        .WithMetaData("Expires", DateTime.Now.AddYears(10).ToString("R"))
        .WithBucketName(this.bucketName)
        .WithCannedACL(S3CannedACL.PublicRead)
        .WithTimeout(60 * 60 * 1000) // 1 hour
        .WithReadWriteTimeout(60 * 60 * 1000) // 1 hour
        .WithKey(FixPathForS3(virtualPath));

      var contentType = virtualPath.Substring(virtualPath.LastIndexOf(".", StringComparison.Ordinal));
      if (string.IsNullOrWhiteSpace(contentType)) {
        request.ContentType = contentType;
      }

      request.WithInputStream(inputStream);
      using (this.s3.PutObject(request)) { }

      if (FileWritten != null)
        FileWritten.Invoke(this, new FileEventArgs(FixPathForN2(virtualPath), null));
    }
开发者ID:njmube,项目名称:N2.S3FileSystem,代码行数:20,代码来源:S3FileSystem.cs

示例8: PutS3File

        /// <summary>
        /// Copies an InputStream to Amazon S3 and grants access to MessageGears.
        /// </summary>
        /// <param name="stream">
        /// An input stream for the data to be copied to S3.
        /// </param>
        /// <param name="bucketName">
        /// The name of the S3 bucket where the file will be copied.
        /// </param>
        /// <param name="key">
        /// The S3 key of the file to be created.
        /// </param>
        public void PutS3File(Stream stream, String bucketName, String key)
        {
            // Check to see if the file already exists in S3
            ListObjectsRequest listRequest = new ListObjectsRequest().WithBucketName(bucketName).WithPrefix(key);
            ListObjectsResponse listResponse = listFiles(listRequest);
            if(listResponse.S3Objects.Count > 0)
            {
                String message = "File " + key + " already exists.";
                log.Warn("PutS3File failed: " + message);
                throw new ApplicationException(message);
            }

            // Copy a file to S3
            PutObjectRequest request = new PutObjectRequest().WithKey(key).WithBucketName(bucketName).WithTimeout(properties.S3PutTimeoutSecs * 1000);
            request.WithInputStream(stream);
            putWithRetry(request);
            setS3PermissionsWithRetry(bucketName, key);

            log.Info("PutS3File successful: " + key);
        }
开发者ID:messagegears,项目名称:messagegears-csharp-sdk,代码行数:32,代码来源:MessageGearsAwsClient.cs

示例9: SavePrivate

        public override string SavePrivate(string domain, string path, Stream stream, DateTime expires)
        {
            using (AmazonS3 client = GetClient())
            {
                var request = new PutObjectRequest();
                string objectKey = MakePath(domain, path);
                request.WithBucketName(_bucket)
                    .WithKey(objectKey)
                    .WithCannedACL(S3CannedACL.BucketOwnerFullControl)
                    .WithContentType("application/octet-stream")
                    .WithMetaData("private-expire", expires.ToFileTimeUtc().ToString());

                var headers = new NameValueCollection();
                headers.Add("Cache-Control", string.Format("public, maxage={0}", (int)TimeSpan.FromDays(5).TotalSeconds));
                headers.Add("Etag", (DateTime.UtcNow.Ticks).ToString());
                headers.Add("Last-Modified", DateTime.UtcNow.ToString("R"));
                headers.Add("Expires", DateTime.UtcNow.Add(TimeSpan.FromDays(5)).ToString("R"));
                headers.Add("Content-Disposition", "attachment");
                request.AddHeaders(headers);

                request.WithInputStream(stream);
                client.PutObject(request);
                //Get presigned url
                GetPreSignedUrlRequest pUrlRequest = new GetPreSignedUrlRequest()
                    .WithBucketName(_bucket)
                    .WithExpires(expires)
                    .WithKey(objectKey)
                    .WithProtocol(Protocol.HTTP)
                    .WithVerb(HttpVerb.GET);

                string url = client.GetPreSignedURL(pUrlRequest);
                //TODO: CNAME!
                return url;
            }
        }
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:35,代码来源:S3Storage.cs

示例10: Save

        public Uri Save(string domain, string path, Stream stream, string contentType,
                                 string contentDisposition, ACL acl)
        {
            bool postWriteCheck = false;
            if (QuotaController != null)
            {
                try
                {
                    QuotaController.QuotaUsedAdd(_modulename, domain, _dataList.GetData(domain), stream.Length);
                }
                catch (Exception)
                {
                    postWriteCheck = true;
                }
            }


            using (AmazonS3 client = GetClient())
            {
                var request = new PutObjectRequest();
                string mime = string.IsNullOrEmpty(contentType)
                                  ? MimeMapping.GetMimeMapping(Path.GetFileName(path))
                                  : contentType;

                request.WithBucketName(_bucket)
                    .WithKey(MakePath(domain, path))
                    .WithCannedACL(acl == ACL.Auto ? GetDomainACL(domain) : GetS3Acl(acl))
                    .WithContentType(mime);

                var headers = new NameValueCollection();
                headers.Add("Cache-Control", string.Format("public, maxage={0}", (int)TimeSpan.FromDays(5).TotalSeconds));
                headers.Add("Etag", (DateTime.UtcNow.Ticks).ToString());
                headers.Add("Last-Modified", DateTime.UtcNow.ToString("R"));
                headers.Add("Expires", DateTime.UtcNow.Add(TimeSpan.FromDays(5)).ToString("R"));
                if (!string.IsNullOrEmpty(contentDisposition))
                {

                    headers.Add("Content-Disposition", contentDisposition);
                }
                else if (mime == "application/octet-stream")
                {
                    headers.Add("Content-Disposition", "attachment");
                }

                request.AddHeaders(headers);

                //Send body
                var buffered = stream.GetBuffered();
                if (postWriteCheck)
                {
                    QuotaController.QuotaUsedAdd(_modulename, domain, _dataList.GetData(domain), buffered.Length);
                }
                request.AutoCloseStream = false;

                request.WithInputStream(buffered);
                client.PutObject(request);
                InvalidateCloudFront(MakePath(domain, path));

                return GetUri(domain, path);
            }
        }
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:61,代码来源:S3Storage.cs

示例11: UploadFile

        private static void UploadFile(FileInfo fileInfo)
        {
            System.Console.WriteLine("Uploading " + fileInfo.Name);
            using (FileStream inputFileStream = new FileStream(fileInfo.FullName, FileMode.Open))
            using (MemoryStream outputMemoryStream = new MemoryStream())
            using (CryptoStream cryptoStream = new CryptoStream(outputMemoryStream, _aesEncryptor, CryptoStreamMode.Write))
            {
                int data;
                while ((data = inputFileStream.ReadByte()) != -1)
                {
                    cryptoStream.WriteByte((byte)data);
                }
                cryptoStream.FlushFinalBlock();

                PutObjectRequest createRequest = new PutObjectRequest();
                createRequest.WithMetaData("x-amz-meta-LWT", fileInfo.LastWriteTime.ToString("G"));
                createRequest.WithBucketName(BucketName);
                createRequest.WithKey(fileInfo.Name);
                createRequest.WithInputStream(outputMemoryStream);

                _amazonS3Client.PutObject(createRequest);
            }
        }
开发者ID:kakaruto,项目名称:S3Sync,代码行数:23,代码来源:Program.cs

示例12: UploadToS3

		private void UploadToS3(string backupPath, PeriodicBackupSetup localBackupConfigs)
		{
			var awsRegion = RegionEndpoint.GetBySystemName(localBackupConfigs.AwsRegionEndpoint) ?? RegionEndpoint.USEast1;

			using (var client = new Amazon.S3.AmazonS3Client(awsAccessKey, awsSecretKey, awsRegion))
			using (var fileStream = File.OpenRead(backupPath))
			{
				var key = Path.GetFileName(backupPath);
				var request = new PutObjectRequest();
				request.WithMetaData("Description", GetArchiveDescription());
				request.WithInputStream(fileStream);
				request.WithBucketName(localBackupConfigs.S3BucketName);
				request.WithKey(key);

				using (client.PutObject(request))
				{
					logger.Info(string.Format("Successfully uploaded backup {0} to S3 bucket {1}, with key {2}",
											  Path.GetFileName(backupPath), localBackupConfigs.S3BucketName, key));
				}
			}
		}
开发者ID:DanielDar,项目名称:ravendb,代码行数:21,代码来源:PeriodicBackupTask.cs

示例13: CopyImage

        private static void CopyImage(object o)
        {
            UserData u = (UserData)o;

              try
              {
            string imagePath = String.Format("{0}\\L{1:00}\\R{2:x8}\\C{3:x8}.{4}", TileDirectory, u.Level, u.Row, u.Column, ContentType == "image/png" ? "png" : "jpg");

            if (File.Exists(imagePath))
            {
              byte[] file = File.ReadAllBytes(imagePath);

              PutObjectRequest putObjectRequest = new PutObjectRequest();
              putObjectRequest.WithBucketName(BucketName);
              putObjectRequest.WithKey(String.Format("{0}/{1}/{2}/{3}", MapName, u.Level, u.Row, u.Column));
              putObjectRequest.WithInputStream(new MemoryStream(file));
              putObjectRequest.WithContentType(ContentType);
              putObjectRequest.WithCannedACL(S3CannedACL.PublicRead);

              _s3Client.PutObject(putObjectRequest);
            }
              }
              catch (Exception ex)
              {
              }
              finally
              {
            _threadPool.Release();
              }
        }
开发者ID:agrc,项目名称:tile-etl,代码行数:30,代码来源:EtlToS3.cs

示例14: UploadImage

        /// <summary>
        /// To upload an image to amazon service bucket.
        /// </summary>
        /// <param name="imageBytesToUpload">image in byte array</param>
        /// <param name="contentType">content type of the image.</param>
        /// <returns>Url of the image from amazon web service</returns>
        public string UploadImage(byte[] imageBytesToUpload, string contentType)
        {
            try
            {
                using (var client = GetClient)
                {
                    string keyName = Guid.NewGuid().ToString();
                    using (MemoryStream mStream = new MemoryStream(imageBytesToUpload))
                    {
                        PutObjectRequest request = new PutObjectRequest();
                        request.WithBucketName(ImagesBucketName)
                            .WithKey(keyName);

                        request.WithContentType(contentType);

                        request.WithInputStream(mStream);

                        S3Response response = client.PutObject(request);

                        response.Dispose();
                    }

                    GetPreSignedUrlRequest requestUrl = new GetPreSignedUrlRequest()
                                                          .WithBucketName(ImagesBucketName)
                                                          .WithKey(keyName)
                                                          .WithProtocol(Protocol.HTTP)
                                                          .WithExpires(DateTime.Now.AddYears(10));

                    return client.GetPreSignedURL(requestUrl);
                }
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                if (amazonS3Exception.ErrorCode != null &&
                    (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") ||
                    amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    throw new Exception("Please check the provided AWS Credentials.");

                }
                else
                {
                    throw new Exception(string.Format("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message));
                }
            }
        }
开发者ID:parm-ameotech,项目名称:amazon-bucket-management,代码行数:52,代码来源:AmazonService.cs

示例15: UploadDocument

        /// <summary>
        /// To upload a agreement pdf to the svn amazon web service.
        /// </summary>
        /// <param name="pdfBytesToUpload">agreement pdf in byte array</param>
        /// <param name="pdfDocumentId">agreement id of the customer object</param>
        public void UploadDocument(byte[] pdfBytesToUpload, string pdfDocumentId, DocType documentType = DocType.PDF)
        {
            try
            {
                using (var client = GetClient)
                {
                    using (MemoryStream mStream = new MemoryStream(pdfBytesToUpload))
                    {
                        PutObjectRequest request = new PutObjectRequest();
                        request.WithBucketName(DocsBucketName)
                            .WithKey(pdfDocumentId);

                        if (documentType == DocType.PDF)
                            request.WithContentType("application/pdf");
                        else if (documentType == DocType.HTML)
                            request.WithContentType("text/html");
                        else
                            request.WithContentType("application/pdf");

                        request.WithInputStream(mStream);

                        S3Response response = client.PutObject(request);
                        response.Dispose();
                    }
                }
            }
            catch (AmazonS3Exception amazonS3Exception)
            {
                if (amazonS3Exception.ErrorCode != null &&
                    (amazonS3Exception.ErrorCode.Equals("InvalidAccessKeyId") ||
                    amazonS3Exception.ErrorCode.Equals("InvalidSecurity")))
                {
                    throw new Exception("Please check the provided AWS Credentials.");

                }
                else
                {
                    throw new Exception(string.Format("An error occurred with the message '{0}' when writing an object", amazonS3Exception.Message));
                }
            }
        }
开发者ID:parm-ameotech,项目名称:amazon-bucket-management,代码行数:46,代码来源:AmazonService.cs


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