Reputation: 55
i am trying to upload an image to azure blob storage, the problem m facing is the image is getting successfully uploaded but the name of the image on azure is randomly generated by the azure itself, i want to name the image myself from the code
following is the code which i am using
var multer = require('multer')
var MulterAzureStorage = require('multer-azure-storage')
var upload = multer({
storage: new MulterAzureStorage({azureStorageConnectionString:
'DefaultEndpointsProtocol=https;AccountName=mystorageaccount;
AccountKey=mykey;EndpointSuffix=core.windows.net',
containerName: 'photos',
containerSecurity: 'blob',
fileName : ?//how to use this options properties
})
} )
Upvotes: 1
Views: 2127
Reputation: 24148
According to the README.md
description of MantaCodeDevs/multer-azure-storage
, the fileName
optional property must be a function which return a custom file name as the blob name stored into Azure Blob Storage.
Otherwise when fileName
is not a function, it will use the default blobName
function below to generate a unique name to avoid naming conflicts.
const blobName = (file) => {
let name = file.fieldname + '-' + uuid.v4() + path.extname(file.originalname)
file.blobName = name
return name
}
So I test it with my sample code below, it works for uploading a 1.png
file as blob into Azure Blob Storage.
var getFileName = function(file) {
return '1.png';
// or return file.originalname;
// or return file.name;
}
var upload = multer({
storage: new MulterAzureStorage({
azureStorageConnectionString: 'DefaultEndpointsProtocol=https;AccountName=<your account name>;AccountKey=<your account key>;EndpointSuffix=core.windows.net',
containerName: 'test',
containerSecurity: 'blob',
fileName: getFileName
})
});
Upvotes: 4