Exemple #1
0
        async public static Task UploadFile(string localFilePath, string remoteFilePath, string filename)
        {
            try
            {
                bool bucketExists = await BucketExist();

                if (!bucketExists)
                {
                    await S3Utils.CreateBucket();
                }

                var requestObject = new PutObjectRequest();
                requestObject.BucketName = S3Utils.BUCKET_NAME.ToLowerInvariant();
                requestObject.FilePath   = localFilePath;
                requestObject.Key        = string.Format("{0}/{1}", remoteFilePath.ToLowerInvariant(), filename);
                requestObject.CannedACL  = S3CannedACL.AuthenticatedRead;

                await S3Client.PutObjectAsync(requestObject);

                System.Diagnostics.Debug.WriteLine("File uploaded to S3 Bucket");
            }
            catch (AmazonS3Exception s3Exception)
            {
                System.Diagnostics.Debug.WriteLine("Upload failed. " + s3Exception.Message);
            }
        }
Exemple #2
0
        public static async void UploadPhoto(byte[] buffer, string localUrl, string remoteUrl, string fileName, Action completion, Action failure)
        {
            IFile file = await FileSystemUtils.CreateIFileAtPath(localUrl);

            using (System.IO.Stream stream = await file.OpenAsync(PCLStorage.FileAccess.ReadAndWrite))
            {
                stream.Write(buffer, 0, buffer.Length);
            }

            try
            {
                await S3Utils.UploadFile(file.Path, remoteUrl, fileName);

                var sucessful = await S3Utils.DownloadFile(file.Path, remoteUrl, fileName);

                if (sucessful)
                {
                    completion?.Invoke();
                }
                else
                {
                    failure?.Invoke();
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
                System.Diagnostics.Debug.WriteLine(ex.StackTrace);
                failure?.Invoke();
            }
        }
Exemple #3
0
 public string GetRemoteHeaderUrlCached()
 {
     if (String.IsNullOrEmpty(remoteHeaderUrlCached))
     {
         remoteHeaderUrlCached = S3Utils.GetPresignedURL(RemoteHeaderURL, "Header.png", S3Utils.DefaultExpiry);
     }
     return(remoteHeaderUrlCached);
 }
Exemple #4
0
 public string GetRemoteLogoUrlCached()
 {
     remoteLogoUrlCached = String.IsNullOrEmpty(remoteLogoUrlCached) ? S3Utils.GetPresignedURL(RemoteLogoURL, "Logo.png", S3Utils.DefaultExpiry) : remoteLogoUrlCached;
     return(remoteLogoUrlCached);
 }
Exemple #5
0
 public string GetRemoteProfileImageUrlCached()
 {
     remoteProfileImageUrlCached = String.IsNullOrEmpty(remoteProfileImageUrlCached) ? S3Utils.GetPresignedURL(RemoteProfileImageURL, "Profile.png", S3Utils.DefaultExpiry) : remoteProfileImageUrlCached;
     return(remoteProfileImageUrlCached);
 }