private void SaveImageToS3()
        {
            try
            {
                var picture = new S3PictureEntity
                {
                    FileName     = lblLoadPictureFromLocal.Text,
                    S3Image      = loadedPictureBox.Image,
                    SafeFileName = lblLoadPictureFromLocal.Text
                };

                var key = S3Library.SaveImageToS3(CurrentConnectionProfile, picture);

                UpdateLoadedS3Image(CurrentConnectionProfile,
                                    new S3MediaEntity()
                {
                    FolderName  = CurrentConnectionProfile.FolderName,
                    BucketName  = CurrentConnectionProfile.BucketName,
                    Key         = key,
                    ProfileName = CurrentConnectionProfile.ProfileName
                });
            }
            catch (Exception exception)
            {
                AddUserMessage(exception.Message);
            }
        }
Exemplo n.º 2
0
        public static S3PictureEntity GetAPicture()
        {
            S3PictureEntity s3PictureEntity = new S3PictureEntity();

            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                openFileDialog.RestoreDirectory = true;

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    //Read the contents of the file into a stream
                    var fileStream = openFileDialog.OpenFile();

                    s3PictureEntity.S3Image      = Image.FromStream(fileStream);
                    s3PictureEntity.FileName     = openFileDialog.FileName;
                    s3PictureEntity.SafeFileName = openFileDialog.SafeFileName;
                }
            }

            return(s3PictureEntity);
        }
Exemplo n.º 3
0
        public string SaveImageToS3(S3ConnectionProfileEntity currentConnectionProfile, S3PictureEntity picture)
        {
            try
            {
                var client = GetAmazonS3Client();

                var stream = DataAccessHelper.GetStream(picture.S3Image, ImageFormat.Jpeg);                 //We are assuming all JPG for our images

                var key = $"{currentConnectionProfile.FolderName}/{picture.FileName}";
                if (currentConnectionProfile.FolderName.Length == 0)
                {
                    key = $"{picture.FileName}";
                }

                var request = new PutObjectRequest
                {
                    BucketName      = currentConnectionProfile.BucketName,
                    InputStream     = stream,
                    ContentType     = "image/jpeg",
                    Key             = key,
                    CannedACL       = S3CannedACL.FindValue(currentConnectionProfile.CannedACL),
                    AutoCloseStream = true,
                    StorageClass    = S3StorageClass.Standard,
                };


                client.PutObject(request);
                return(key);
            }
            catch (Exception exception)
            {
                throw new Exception($"Error {exception.Message}");
            }
        }
Exemplo n.º 4
0
        public static string SaveImageToS3(S3ConnectionProfileEntity currentConnectionProfile, S3PictureEntity picture)
        {
            try
            {
                var key = String.Empty;

                if (currentConnectionProfile.KeyBasedAccessFlag)
                {
                    key = (new AmazonS3V2.DAL.S3Access()).SaveImageToS3(currentConnectionProfile, picture);
                }
                else
                {
                    key = (new AmazonS3V3.DAL.S3Access()).SaveImageToS3(currentConnectionProfile, picture);
                }

                return(key);
            }
            catch (Exception exception)
            {
                throw new Exception($"Error {exception.Message}");
            }
        }
Exemplo n.º 5
0
 string IMediaRequests.SaveImageToS3(S3ConnectionProfileEntity currentConnectionProfile, S3PictureEntity picture)
 {
     return(SaveImageToS3(currentConnectionProfile, picture));
 }
Exemplo n.º 6
0
 public static string SaveImageToS3(S3ConnectionProfileEntity currentConnectionProfile, S3PictureEntity picture)
 {
     try
     {
         return(DataAccess.SaveImageToS3(currentConnectionProfile, picture));
     }
     catch (Exception exception)
     {
         throw new Exception(exception.Message);
     }
 }