I am using azure blob storage standard account. When I try to upload files, it throws the error 'BlobTypeNotSupported'. I know standard account doesn't support 'Block Blobs'. Is there any other way to upload files using standard account?
I tried in my environment and got below results:
I created a standard storage account through azure portal :
I used the below code to upload images using nest.js
Code:
import { BlobServiceClient, BlockBlobClient } from '@azure/storage-blob';
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
azureConnection = "< Connection string >";
containerName = "test";
getBlobClient(imageName:string):BlockBlobClient{
const blobClientService = BlobServiceClient.fromConnectionString(this.azureConnection);
const containerClient = blobClientService.getContainerClient(this.containerName);
const blobClient = containerClient.getBlockBlobClient(imageName);
return blobClient;
}
async upload(file:Express.Multer.File){
const blobClient = this.getBlobClient(file.originalname);
await blobClient.uploadData(file.buffer);
}
}
console:
Postman: You can use the post request to upload image via postman.
Portal:
The above request worked successfully and uploaded file through azure storage standard account using nest.js with Block-blob type.
Reference:
NestJS API File Operations Using Azure Blob Storage (learmoreseekmore.com) by Naveen.