类型“BlockBlobClient”上不存在属性“uploadData”。ts
时间: 2023-09-08 14:16:45 浏览: 41
这个错误通常出现在使用 Azure Blob Storage 的 JavaScript SDK 时,因为在最新版本中,`BlockBlobClient` 类上已经不存在 `uploadData` 属性。相反,您应该使用 `uploadData` 方法来上传数据。
以下是使用 `uploadData` 方法上传数据的示例代码:
```typescript
import { BlobServiceClient, StorageSharedKeyCredential } from "@azure/storage-blob";
const account = "<your-storage-account-name>";
const accountKey = "<your-storage-account-key>";
const containerName = "<your-container-name>";
const blobName = "<your-blob-name>";
const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);
const blobServiceClient = new BlobServiceClient(
`https://${account}.blob.core.windows.net`,
sharedKeyCredential
);
const containerClient = blobServiceClient.getContainerClient(containerName);
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const data = "Hello, world!";
const uploadBlobResponse = await blockBlobClient.uploadData(data);
```
请注意,`uploadData` 方法接受一个参数,即要上传的数据。此外,还有其他可用的上传方法,如 `uploadStream` 和 `uploadFile`,您可以根据自己的需要选择合适的方法。
相关推荐
![crx](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)