예제 #1
0
 /// <summary>
 /// Adds an object to S3 by reading the specified amount of data from the given stream.
 /// </summary>
 public void AddObject(Stream inputStream, long bytes, string bucketName, string key,
                       string contentType, CannedAcl acl)
 {
     AddObject(bucketName, key, bytes, contentType, acl, stream =>
     {
         CopyStream(inputStream, stream, bytes,
                    CreateProgressCallback(bucketName, key, bytes, AddObjectProgress));
         stream.Flush();
     });
 }
예제 #2
0
        /// <summary>
        /// Adds an object to S3 by acquiring the upload stream then allowing the given
        /// function to handle writing data into it.
        /// </summary>
        public void AddObject(string bucketName, string key, long bytes, string contentType,
                              CannedAcl acl, Action <Stream> action)
        {
            var request = new AddObjectRequest(this, bucketName, key)
            {
                ContentLength = bytes,
                CannedAcl     = acl
            };

            if (contentType != null) // if specified
            {
                request.ContentType = contentType;
            }

            request.PerformWithRequestStream(action);
        }
예제 #3
0
        /// <summary>
        /// Copies an object from one bucket to another with the given canned ACL.
        /// </summary>
        public void CopyObject(string sourceBucketName, string sourceKey,
                               string destBucketName, string destKey, CannedAcl acl)
        {
            var request = new CopyObjectRequest(this, sourceBucketName, sourceKey,
                                                destBucketName, destKey)
            {
                CannedAcl = acl
            };

            CopyObjectResponse response = request.GetResponse();

            response.Close();

            if (response.Error != null)
            {
                throw response.Error;
            }
        }
예제 #4
0
파일: S3Service.cs 프로젝트: ngs-doo/revenj
 /// <summary>
 /// Copies an object within a bucket and assigns the given canned ACL.
 /// </summary>
 public void CopyObject(string bucketName, string sourceKey, string destKey, CannedAcl acl)
 {
     CopyObject(bucketName, sourceKey, bucketName, destKey, acl);
 }
예제 #5
0
파일: S3Service.cs 프로젝트: ngs-doo/revenj
        /// <summary>
        /// Copies an object from one bucket to another with the given canned ACL.
        /// </summary>
        public void CopyObject(string sourceBucketName, string sourceKey,
            string destBucketName, string destKey, CannedAcl acl)
        {
            var request = new CopyObjectRequest(this, sourceBucketName, sourceKey,
                destBucketName, destKey) { CannedAcl = acl };

            CopyObjectResponse response = request.GetResponse();
            response.Close();

            if (response.Error != null)
                throw response.Error;
        }
예제 #6
0
파일: S3Service.cs 프로젝트: ngs-doo/revenj
 /// <summary>
 /// Uploads the contents of a string to S3. This method is only appropriate for
 /// small objects and testing. The UTF-8 encoding will be used.
 /// </summary>
 public void AddObjectString(string contents, string bucketName, string key,
     string contentType, CannedAcl acl)
 {
     using (var inputStream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
         AddObject(inputStream, bucketName, key, contentType, acl);
 }
예제 #7
0
파일: S3Service.cs 프로젝트: ngs-doo/revenj
 /// <summary>
 /// Adds an object to S3 by reading all the data in the given stream. The stream must support
 /// the Length property.
 /// </summary>
 public void AddObject(Stream inputStream, string bucketName, string key,
     string contentType, CannedAcl acl)
 {
     AddObject(inputStream, inputStream.Length, bucketName, key, contentType, acl);
 }
예제 #8
0
파일: S3Service.cs 프로젝트: ngs-doo/revenj
 /// <summary>
 /// Adds an object to S3 by reading the specified amount of data from the given stream.
 /// </summary>
 public void AddObject(Stream inputStream, long bytes, string bucketName, string key,
     string contentType, CannedAcl acl)
 {
     AddObject(bucketName, key, bytes, contentType, acl, stream =>
     {
         CopyStream(inputStream, stream, bytes,
             CreateProgressCallback(bucketName, key, bytes, AddObjectProgress));
         stream.Flush();
     });
 }
예제 #9
0
파일: S3Service.cs 프로젝트: ngs-doo/revenj
        /// <summary>
        /// Adds an object to S3 by acquiring the upload stream then allowing the given
        /// function to handle writing data into it.
        /// </summary>
        public void AddObject(string bucketName, string key, long bytes, string contentType,
            CannedAcl acl, Action<Stream> action)
        {
            var request = new AddObjectRequest(this, bucketName, key)
            {
                ContentLength = bytes,
                CannedAcl = acl
            };

            if (contentType != null) // if specified
                request.ContentType = contentType;

            request.PerformWithRequestStream(action);
        }
예제 #10
0
        private UserPhoto ProcessMainPhotoItem(
            HttpPostedFileBase file, 
            UserPhoto up1, 
            int currentUserId, 
            CannedAcl acl, 
            S3Service s3, 
            string photoOne, 
            string photoTwo, 
            string photoThree, 
            string photoEdited,
            Bitmap photoBitmap)
        {
            string rawPhotoFileName = AddPhotoToBucket(file, acl, s3, photoBitmap, false);
            string profilePhotoFileName = AddPhotoToBucket(file, acl, s3, photoBitmap, true, 300,  300);

            if (string.IsNullOrEmpty(_uad.ProfileThumbPicURL) ||
                _ups.Count == 2 && photoEdited == photoOne)
            {
                _uad.ProfilePicURL = profilePhotoFileName;
                _uad.RawProfilePicUrl = rawPhotoFileName;
            }
            else
            {
                if (up1 == null)
                {
                    up1 = new UserPhoto();
                }

                if (_mu != null) up1.UserAccountID = currentUserId;

                up1.RawPicUrl = rawPhotoFileName;
                up1.PicURL = profilePhotoFileName;

                if ((_ups.Count > 0 && photoEdited == photoTwo) || (_ups.Count == 0))
                {
                    up1.RankOrder = 1;
                }
                else if ((_ups.Count > 1 && photoEdited == photoThree) || _ups.Count == 1)
                {
                    up1.RankOrder = 2;
                }

                if (_ups.Count == 1 && _ups[0].RankOrder == 2)
                {
                    _ups[0].RankOrder = 1;
                    _ups[0].Update();
                }
            }

            return up1;
        }
예제 #11
0
        private static string AddPhotoToBucket(
            HttpPostedFileBase file, 
            CannedAcl acl, 
            S3Service s3, 
            Bitmap photoBitmap, 
            bool resize, 
            int width = 1, 
            int height = 1)
        {
            string profilePhotoFileName = Utilities.CreateUniqueContentFilename(file);
            Image rawPhoto = photoBitmap;

            if (resize)
            {
                Image image = ImageResize.FixedSize(imgPhoto: rawPhoto, width: width, height: height, bgColor: Color.Black);
                Stream profilePhotoStream = image.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    profilePhotoStream,
                    profilePhotoStream.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    profilePhotoFileName,
                    file.ContentType,
                    acl);
            }
            else
            {
                Stream image = rawPhoto.ToAStream(ImageFormat.Jpeg);

                s3.AddObject(
                    image,
                    image.Length,
                    AmazonCloudConfigs.AmazonBucketName,
                    profilePhotoFileName,
                    file.ContentType,
                    acl);
            }

            return profilePhotoFileName;
        }
예제 #12
0
 /// <summary>
 /// Copies an object within a bucket and assigns the given canned ACL.
 /// </summary>
 public void CopyObject(string bucketName, string sourceKey, string destKey, CannedAcl acl)
 {
     CopyObject(bucketName, sourceKey, bucketName, destKey, acl);
 }
예제 #13
0
 /// <summary>
 /// Uploads the contents of a string to S3. This method is only appropriate for
 /// small objects and testing. The UTF-8 encoding will be used.
 /// </summary>
 public void AddObjectString(string contents, string bucketName, string key,
                             string contentType, CannedAcl acl)
 {
     using (var inputStream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
         AddObject(inputStream, bucketName, key, contentType, acl);
 }
예제 #14
0
 /// <summary>
 /// Uploads the contents of an existing local file to S3.
 /// </summary>
 public void AddObject(string inputFile, string bucketName, string key,
                       string contentType, CannedAcl acl)
 {
     using (Stream inputStream = File.OpenRead(inputFile))
         AddObject(inputStream, inputStream.Length, bucketName, key, contentType, acl);
 }
예제 #15
0
 /// <summary>
 /// Adds an object to S3 by reading all the data in the given stream. The stream must support
 /// the Length property.
 /// </summary>
 public void AddObject(Stream inputStream, string bucketName, string key,
                       string contentType, CannedAcl acl)
 {
     AddObject(inputStream, inputStream.Length, bucketName, key, contentType, acl);
 }
예제 #16
0
파일: S3Service.cs 프로젝트: rdkhatch/LitS3
 /// <summary>
 /// Uploads the contents of an existing local file to S3.
 /// </summary>
 public void AddObject(string inputFile, string bucketName, string key,
     string contentType, CannedAcl acl)
 {
     using (Stream inputStream = File.OpenRead(inputFile))
         AddObject(inputStream, inputStream.Length, bucketName, key, contentType, acl);
 }