Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
Strange behavior saving a file into Azure blob storage

I am using @azure/storage-blob:^12.8.0, @azure/storage-queue: ^12.7.0 packages to authenticate and connect to Azure blob storage, authentication goes through Managed Identities and the destination granted access with Storage Blob Data Contributor role, below is my code

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');

everything works except that the file is stored in the wrong place, for example, by calling store('folder1/folder2/folder3', 'path/file.jpg') I expect the file to be stored at folder1/folder2/folder3/file.jpg but the file gets stored at C1/folder1/folder2/folder3/file.jpg C1 is the name of the container which is wrong and should not happen, the code runs as Azure functions node.

to make it clear, the expectation is

  • C1 (the container)
    • folder1
      • folder2
        • folder3
          • file.jpg

but the actual result is

  • C1 (the container)
    • C1
      • folder1
        • folder2
          • folder3
            • file.jpg

Any idea ?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try with this code , I tried this code in my system able to store the file with folder structure in azure container

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);

OUTPUT

enter image description here

The files are saved in container in azure storage

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório

0

The problem was a wrong value coming from the AppSettings which was not obvious in the code. it should be https://accountname.blob.core.windows.net but instead, it was https://accountname.blob.core.windows.net/ContainerName.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda