Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!