/// <summary>Appends text to Amazon S3 storage object.</summary>
 /// <param name="obj">Object info.</param>
 /// <param name="content">Content to append.</param>
 public void AppendTextToObject(IS3ObjectInfo obj, string content)
 {
     if (this.ObjectExists(obj))
     {
         if (obj.IsLocked)
         {
             throw new Exception($"[IS3ObjectInfoProvider.AppendTextToObject]: Couldn't upload object {obj.Key} because it is used by another process.");
         }
         obj.Lock();
         System.IO.Stream objectContent = this.GetObjectContent(obj, System.IO.FileMode.Open,
                                                                System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite, 4096);
         string str = null;
         using (CMS.IO.StreamReader streamReader = CMS.IO.StreamReader.New(objectContent))
         {
             str = streamReader.ReadToEnd();
         }
         PutObjectRequest putRequest = CreatePutRequest(obj.Key, obj.BucketName);
         putRequest.ContentBody = str + content;
         PutObjectResponse response = this.S3Client.PutObject(putRequest);
         this.SetS3ObjectMetadaFromResponse(obj, response, 0L);
         FileDebug.LogFileOperation(PathHelper.GetPathFromObjectKey(obj.Key, true), nameof(AppendTextToObject), "Custom Amazon");
         obj.UnLock();
         RemoveRequestCache(obj.Key);
     }
     else
     {
         this.PutTextToObject(obj, content);
     }
 }
        /// <summary>Puts data from stream to Amazon S3 storage.</summary>
        /// <param name="obj">Object info.</param>
        /// <param name="stream">Stream to upload.</param>
        public void PutDataFromStreamToObject(IS3ObjectInfo obj, System.IO.Stream stream)
        {
            if (obj.IsLocked)
            {
                throw new Exception($"[IS3ObjectInfoProvider.PutDataFromStreamToObject]: Couldn't upload object {obj.Key} because it is used by another process.");
            }
            obj.Lock();
            string bucketName = obj.BucketName;
            long   length     = stream.Length;

            if (length > RECOMMENDED_SIZE_FOR_MULTIPART_UPLOAD)
            {
                CompleteMultipartUploadResponse response = this.MultiPartUploader.UploadFromStream(obj.Key, bucketName, stream);
                this.SetS3ObjectMetadaFromResponse(obj, response, length);
            }
            else
            {
                PutObjectRequest putRequest = CreatePutRequest(obj.Key, bucketName);
                putRequest.InputStream = stream;
                PutObjectResponse response = this.S3Client.PutObject(putRequest);
                this.SetS3ObjectMetadaFromResponse(obj, response, length);
            }
            FileDebug.LogFileOperation(PathHelper.GetPathFromObjectKey(obj.Key, true), "PutStreamToObject", "Custom Amazon");
            obj.UnLock();
            RemoveRequestCache(obj.Key);
        }
        /// <summary>Puts text to Amazon S3 storage object.</summary>
        /// <param name="obj">Object info.</param>
        /// <param name="content">Content to add.</param>
        public void PutTextToObject(IS3ObjectInfo obj, string content)
        {
            if (obj.IsLocked)
            {
                throw new Exception($"[IS3ObjectInfoProvider.PutTextToObject]: Couldn't upload object {obj.Key} because it is used by another process.");
            }
            string pathFromObjectKey = PathHelper.GetPathFromObjectKey(obj.Key, true);

            obj.Lock();
            PutObjectRequest putRequest = CreatePutRequest(obj.Key, GetBucketName(pathFromObjectKey));

            putRequest.ContentBody = content;
            PutObjectResponse response = this.S3Client.PutObject(putRequest);

            this.SetS3ObjectMetadaFromResponse(obj, response, 0L);
            FileDebug.LogFileOperation(PathHelper.GetPathFromObjectKey(obj.Key, true), nameof(PutTextToObject), "Custom Amazon");
            obj.UnLock();
            RemoveRequestCache(obj.Key);
        }