微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

TypeError 无法在 typeScript Azure blob 上传中设置未定义的属性“大小”

如何解决TypeError 无法在 typeScript Azure blob 上传中设置未定义的属性“大小”

我正在尝试将文件从本地路径上传到 azure blob 存储。下面是代码上传时出现错误,如 TypeError cannot set property 'size of' undefined

使用 SAS 令牌成功连接到 Azure Blob 存储(从控制台观察),但在内部获取错误获取文件大小。你能否在这里提出任何建议来解决这个问题。 注意:使用 StorageSharedKeyCredential,与 Azure 本身的连接未成功,显示存储共享密钥凭据不是构造函数

enter image description here

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)

;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。