将文件保存到 Azure Blob 存储中的奇怪行为

Strange behavior saving a file into Azure blob storage

我正在使用 @azure/storage-blob:^12.8.0, @azure/storage-queue: ^12.7.0 包进行身份验证并连接到 Azure blob 存储,身份验证通过托管身份进行,目的地授予具有 Storage Blob Data Contributor 角色的访问权限,下面是我的代码

const credentialOptions = {
    managedIdentityClientId: process.env.MANAGED_IDENTITY_CLIENT_ID
};

const CONTAINER_NAME = 'C1';
const credential = new DefaultAzureCredential(credentialOptions);
const blobSvc = new BlobServiceClient(process.env.STORAGE_HOST, credential);
const containerClient = blobSvc.getContainerClient(CONTAINER_NAME);

export const store = async (file: string, folder: string) => {    
    const fileName = path.basename(file);
    const blob = `${folder}/${fileName}`;
    try {
        console.debug(`starting store ${blob}...`);      
        const blobClient = containerClient.getBlockBlobClient(blob);
        await blobClient.uploadFile(file);
        console.debug('store done.');
        return blob;
    }
    catch (err) {
        console.error(err);       
        throw Error(err);
    }
};


// in other module 
import {store} from 'BlobStorageHelper';

store('folder1/folder2/folder3', '/temporary/path/to/the/file.jpg');

一切正常,除了文件存储在错误的位置,例如,通过调用 store('folder1/folder2/folder3', 'path/file.jpg') 我希望文件存储在 folder1/folder2/folder3/file.jpg 但文件存储在 C1/folder1/folder2/folder3/file.jpg C1 是错误的容器名称,不应该发生,代码作为 Azure 函数节点运行。

说清楚,期望是

但实际结果是

有什么想法吗?

尝试使用此代码,我在我的系统中尝试过此代码能够将具有文件夹结构的文件存储在 azure 容器中

const blobServiceClient = BlobServiceClient.fromConnectionString("Connection String");
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobName="test1/test2 "+ "/" + "test"
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
const file="C: \blobs\test.txt"
await blockBlobClient.uploadFile(file);
console.log('\nUploading to Azure storage as blob:\n\t', blobName);

输出

文件保存在 Azure 存储的容器中

问题是来自 AppSettings 的错误值,这在代码中并不明显。它应该是 https://accountname.blob.core.windows.net 但实际上是 https://accountname.blob.core.windows.net/ContainerName.