Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

122
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda