最好的解决方法是更新代码以使用新的API。如果您无法更改代码,则可以继续使用弃用的API,但需要知道它们最终可能会被删除。
以下是一个示例,说明如何使用客户库中的新API:
// Create a reference to the blob container using the new BlobServiceClient API.
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(containerName);
// Upload a blob using the new BlobClient API.
BlobClient blobClient = containerClient.GetBlobClient(blobName);
await blobClient.UploadAsync(content);
如果您的代码依赖于弃用的API,则可以通过以下方式解决:
// Create a reference to the blob container using the deprecated CloudStorageAccount API.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference(containerName);
// Upload a blob using the deprecated CloudBlob API.
CloudBlockBlob blob = container.GetBlockBlobReference(blobName);
await blob.UploadFromStreamAsync(content);
请注意,在这种情况下,您应该考虑在有可能的情况下使用新的API来避免将来的更改。