示例#1
0
        public async System.Threading.Tasks.Task <SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> > UploadAsync(System.String ContainerName, System.String StorageFileName, System.IO.Stream FileContents)
        {
            SoftmakeAll.SDK.CloudStorage.Azure.Environment.Validate();

            SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement> OperationResult = new SoftmakeAll.SDK.OperationResult <System.Text.Json.JsonElement>();

            if (SoftmakeAll.SDK.Helpers.String.Extensions.StringExtensions.IsNullOrWhiteSpace(ContainerName, StorageFileName))
            {
                OperationResult.Message = "The ContainerName and StorageFileName cannot be null.";
                return(OperationResult);
            }

            try
            {
                global::Azure.Storage.Blobs.BlobContainerClient BlobContainerClient = new global::Azure.Storage.Blobs.BlobContainerClient(SoftmakeAll.SDK.CloudStorage.Azure.Environment._ConnectionString, ContainerName);
                await BlobContainerClient.CreateIfNotExistsAsync();

                global::Azure.Storage.Blobs.BlobClient BlobClient = BlobContainerClient.GetBlobClient(StorageFileName);
                await BlobClient.UploadAsync(FileContents, true);
            }
            catch (System.Exception ex)
            {
                OperationResult.Message = ex.Message;
                return(OperationResult);
            }

            OperationResult.ExitCode = 0;
            return(OperationResult);
        }