async function createBlobFromLocalPath( containerClient: ContainerClient, blobName: string, uploadFile:Blob, uploadOptions: BlockBlobParallelUploadOptions ): Promise<void> { // create blob client from container client const blockBlobClient = await containerClient.getBlockBlobClient(`${blobName}/${uploadFile.name}`); // upload file to blob storage const uploadResult = await blockBlobClient.uploadStream( uploadFile, {} ); console.log(uploadResult) if (!uploadResult.errorCode) { console.log(`${blobName} succeeded ${uploadResult.date}`); return } console.log(uploadResult) } 提示类型“Blob”的参数不能赋给类型“Readable”的参数。 类型“Blob”缺少类型“Readable”的以下属性: readableAborted, readable, readableDidRead, readableEncoding 及其他 37 项。
时间: 2024-01-25 13:02:54 浏览: 119
同步任务顺序: <li>1.console.log("script- 111");</li>
这段代码中的问题是,`uploadFile` 参数的类型为 `Blob`,但是 `uploadStream` 方法需要传入一个 `Readable` 类型的参数。这两个类型并不兼容,因此会出现类型错误。需要将 `uploadFile` 转换为 `Readable` 类型,可以使用 `stream.Readable.from` 方法来实现。修改后的代码如下:
```
import * as stream from 'stream';
async function createBlobFromLocalPath(
containerClient: ContainerClient,
blobName: string,
uploadFile: Blob,
uploadOptions: BlockBlobParallelUploadOptions
): Promise<void> {
// create blob client from container client
const blockBlobClient = await containerClient.getBlockBlobClient(`${blobName}/${uploadFile.name}`);
// convert Blob to Readable stream
const readableStream = stream.Readable.from(uploadFile);
// upload file to blob storage
const uploadResult = await blockBlobClient.uploadStream(
readableStream,
{},
uploadOptions
);
console.log(uploadResult);
if (!uploadResult.errorCode) {
console.log(`${blobName} succeeded ${uploadResult.date}`);
return;
}
console.log(uploadResult);
}
```
阅读全文