首页 > 解决方案 > 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)

;

标签: typescriptazurefile-uploadazure-blob-storage

解决方案


推荐阅读