Bloom.WebLibraryIntegration.BloomS3Client.UploadSingleFile C# (CSharp) Method

UploadSingleFile() public method

Allows a file to be put into the root of the bucket. Could be enhanced to specify a sub folder path, but I don't need that for the current use.
public UploadSingleFile ( string pathToFile, IProgress progress ) : string
pathToFile string
progress IProgress
return string
        public string UploadSingleFile(string pathToFile, IProgress progress)
        {
            using(var transferUtility = new TransferUtility(GetAmazonS3(_bucketName)))
            {
                var request = new TransferUtilityUploadRequest
                {
                    BucketName = _bucketName,
                    FilePath = pathToFile,
                    Key = Path.GetFileName(pathToFile),
                    CannedACL = S3CannedACL.PublicRead // Allows any browser to download it.
                };
                progress.WriteStatus("Uploading book to Bloom Support...");
                transferUtility.Upload(request);
                return "https://s3.amazonaws.com/" + _bucketName + "/" + HttpUtility.UrlEncode(request.Key);
            }
        }

Usage Example

        public static string UploadBook(string bucketName, string bookZipPath, IProgress progress)
        {
            try
            {
                using(var s3Client = new BloomS3Client(bucketName))
                {
                    var url = s3Client.UploadSingleFile(bookZipPath, progress);
                    progress.WriteMessage("Upload Success");
                    return url;
                }

            }
            catch (WebException e)
            {
                progress.WriteError("There was a problem uploading your book: "+e.Message);
                throw;
            }
            catch (AmazonS3Exception e)
            {
                if (e.Message.Contains("The difference between the request time and the current time is too large"))
                {
                    progress.WriteError(LocalizationManager.GetString("PublishTab.Upload.TimeProblem",
                        "There was a problem uploading your book. This is probably because your computer is set to use the wrong timezone or your system time is badly wrong. See http://www.di-mgt.com.au/wclock/help/wclo_setsysclock.html for how to fix this."));
                }
                else
                {
                    progress.WriteError("There was a problem uploading your book: " + e.Message);
                }
                throw;
            }
            catch (AmazonServiceException e)
            {
                progress.WriteError("There was a problem uploading your book: " + e.Message);
                throw;
            }
            catch (Exception e)
            {
                progress.WriteError("There was a problem uploading your book.");
                progress.WriteError(e.Message.Replace("{", "{{").Replace("}", "}}"));
                progress.WriteVerbose(e.StackTrace);
                throw;
            }
        }
All Usage Examples Of Bloom.WebLibraryIntegration.BloomS3Client::UploadSingleFile