/// <summary> /// set azure blob content /// </summary> /// <param name="fileName">local file path</param> /// <param name="containerName">container name</param> /// <param name="blobName">blob name</param> /// <returns>null if user cancel the overwrite operation, otherwise return destination blob object</returns> internal void SetAzureBlobContent(string fileName, string blobName) { StorageBlob.BlobType type = StorageBlob.BlobType.BlockBlob; if (string.Equals(blobType, BlockBlobType, StringComparison.InvariantCultureIgnoreCase)) { type = StorageBlob.BlobType.BlockBlob; } else if (string.Equals(blobType, PageBlobType, StringComparison.InvariantCultureIgnoreCase)) { type = StorageBlob.BlobType.PageBlob; } else if (string.Equals(blobType, AppendBlobType, StringComparison.InvariantCultureIgnoreCase)) { type = StorageBlob.BlobType.AppendBlob; } else { throw new InvalidOperationException(string.Format( CultureInfo.CurrentCulture, Resources.InvalidBlobType, blobType, blobName)); } if (!string.IsNullOrEmpty(blobName) && !NameUtil.IsValidBlobName(blobName)) { throw new ArgumentException(String.Format(Resources.InvalidBlobName, blobName)); } string filePath = GetFullSendFilePath(fileName); bool isFile = UploadRequests.EnqueueRequest(filePath, type, blobName); if (!isFile) { WriteWarning(String.Format(Resources.CannotSendDirectory, filePath)); } }
/// <summary> /// execute command /// </summary> public override void ExecuteCmdlet() { if (AsJob.IsPresent) { DoBeginProcessing(); } // Validate the Blob Tier matches with blob Type StorageBlob.BlobType type = StorageBlob.BlobType.BlockBlob; if (string.Equals(blobType, BlockBlobType, StringComparison.InvariantCultureIgnoreCase)) { type = StorageBlob.BlobType.BlockBlob; } else if (string.Equals(blobType, PageBlobType, StringComparison.InvariantCultureIgnoreCase)) { type = StorageBlob.BlobType.PageBlob; } else { type = StorageBlob.BlobType.Unspecified; } ValidateBlobTier(type, pageBlobTier, standardBlobTier); if (BlobProperties != null) { ValidateBlobProperties(BlobProperties); } // if FIPS policy is enabled, must use native MD5 if (fipsEnabled) { CloudStorageAccount.UseV1MD5 = false; } string containerName = string.Empty; switch (ParameterSetName) { case ContainerParameterSet: if (ShouldProcess(BlobName, VerbsCommon.Set)) { SetAzureBlobContent(ResolvedFileName, BlobName); containerName = CloudBlobContainer.Name; UploadRequests.SetDestinationContainer(Channel, containerName); } break; case BlobParameterSet: if (ShouldProcess(CloudBlob.Name, VerbsCommon.Set)) { if (CloudBlob is InvalidCloudBlob) { throw new InvalidOperationException("This cmdlet is not supportted on a blob version."); } SetAzureBlobContent(ResolvedFileName, CloudBlob.Name); containerName = CloudBlob.Container.Name; UploadRequests.SetDestinationContainer(Channel, containerName); } break; case ManualParameterSet: default: if (ShouldProcess(BlobName, VerbsCommon.Set)) { SetAzureBlobContent(ResolvedFileName, BlobName); containerName = ContainerName; UploadRequests.SetDestinationContainer(Channel, containerName); } break; } if (AsJob.IsPresent) { DoEndProcessing(); } }