typescript - TypeError 无法在 typeScript Azure blob 上传中设置未定义的属性“大小”
问题描述
我正在尝试将文件从本地路径上传到 azure blob 存储。下面是代码。上传时出现错误,例如TypeError cannot set property 'size of' undefined。
使用 SAS 令牌(从控制台观察到)成功连接到 Azure Blob 存储,但在内部获取错误以获取文件的大小。您能否在这里提出任何建议来解决此问题。注意:使用 StorageSharedKeyCredential 与 Azure 本身的连接没有成功,显示存储共享密钥凭据不是构造函数。
const {
StorageSharedKeyCredential,
BlobServiceClient
} = require('@azure/storage-blob');
const path = require("path");
const localFilePath = "G:/test/download2.jpg";
const STORAGE_ACCOUNT_NAME = "***********";
const containerName = "container1";
const sas = "******************";
const blobServiceClient = new AzureAPI.BlobServiceClient(`https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net${sas}`);
const containerClient = blobServiceClient.getContainerClient(containerName);
const fileName = path.basename(localFilePath);
const blobClient = containerClient.getBlobClient(fileName);
const blockBlobClient = blobClient.getBlockBlobClient();
blockBlobClient.uploadFile(localFilePath)
;
解决方案
推荐阅读
- c# - 将泛型与 GraphType 一起使用
- docker-compose - docker 容器 A 可以使用什么 URL 来访问另一个 docker 容器 B(相同的开发机器,不同的项目)
- excel - 如何使用 Excel VBA 打开 URL 列表并将每个 URL 的屏幕截图保存在我的辅助监视器上
- pandas - Pandas 查询无法识别全局环境中定义的列表
- typescript - 添加 vuex persist 插件后,我无法在路由器中存储
- node.js - 使用快速应用程序关闭多个端口
- angular - 如何在没有 maven 的情况下集成 Angular4+ Spring MVC + Hibernate?
- node.js - 为什么 http 模块不在 node_modules 文件夹中?
- excel - 查找、替换和计算多个值
- javascript - 每个页面都显示相同的内容?