Ejemplo n.º 1
0
        public async Task <Uri> UploadBlob(Stream blobContent, bool isVideo, string reviewId, UploadProgress progressUpdater)
        {
            Uri blobAddress = null;

            try
            {
                var writeCredentials = await ObtainStorageCredentials(StoragePermissionType.Write);

                var sasUri            = $"https://{APIKeys.StorageAccountName}.blob.core.windows.net/" + writeCredentials;
                var blobServiceClient = new BlobServiceClient(new Uri(sasUri));

                var container = blobServiceClient.GetBlobContainerClient(APIKeys.PhotosContainerName);

                var extension = isVideo ? "mp4" : "png";
                var blockBlob = container.GetBlobClient($"{Guid.NewGuid()}.{extension}");

                IDictionary <string, string> metadata = new Dictionary <string, string>();
                metadata.Add("reviewId", reviewId);
                blockBlob.SetMetadata(metadata);
                await blockBlob.UploadAsync(blobContent, null, null, null, progressUpdater);

                blobAddress = blockBlob.Uri;
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"*** Error {ex.Message}");

                return(null);
            }

            return(blobAddress);
        }
Ejemplo n.º 2
0
        public async Task <Uri> UploadBlob(Stream blobContent, bool isVideo, string reviewId, UploadProgress progressUpdater)
        {
            Uri blobAddress = null;

            try
            {
                var writeCredentials = await ObtainStorageCredentials(StoragePermissionType.Write);

                var csa = new Microsoft.WindowsAzure.Storage.CloudStorageAccount(writeCredentials, APIKeys.StorageAccountName, APIKeys.StorageAccountUrlSuffix, true);

                var blobClient = csa.CreateCloudBlobClient();

                var container = blobClient.GetContainerReference(APIKeys.PhotosContainerName);

                var extension = isVideo ? "mp4" : "png";
                var blockBlob = container.GetBlockBlobReference($"{Guid.NewGuid()}.{extension}");

                blockBlob.Metadata.Add("reviewId", reviewId);
                await blockBlob.UploadFromStreamAsync(blobContent, null, null, null, progressUpdater, new CancellationToken());

                blobAddress = blockBlob.Uri;
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"*** Error {ex.Message}");

                return(null);
            }

            return(blobAddress);
        }