Problem in Uploading Image in Azure Blob Storage












0















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









share|improve this question

























  • Seems like this is a question about multer, and not about Azure Storage. Azure Storage doesn't generate random blob names; looks like this is the default behavior for multer when you don't specify a filename. Perhaps look at the multer DiskStorage documentation, which seems to cover it.

    – David Makogon
    Dec 28 '18 at 13:36


















0















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









share|improve this question

























  • Seems like this is a question about multer, and not about Azure Storage. Azure Storage doesn't generate random blob names; looks like this is the default behavior for multer when you don't specify a filename. Perhaps look at the multer DiskStorage documentation, which seems to cover it.

    – David Makogon
    Dec 28 '18 at 13:36
















0












0








0








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









share|improve this question
















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






node.js azure express azure-storage multer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 28 '18 at 21:03







Shubham Sawant

















asked Dec 28 '18 at 12:54









Shubham SawantShubham Sawant

204




204













  • Seems like this is a question about multer, and not about Azure Storage. Azure Storage doesn't generate random blob names; looks like this is the default behavior for multer when you don't specify a filename. Perhaps look at the multer DiskStorage documentation, which seems to cover it.

    – David Makogon
    Dec 28 '18 at 13:36





















  • Seems like this is a question about multer, and not about Azure Storage. Azure Storage doesn't generate random blob names; looks like this is the default behavior for multer when you don't specify a filename. Perhaps look at the multer DiskStorage documentation, which seems to cover it.

    – David Makogon
    Dec 28 '18 at 13:36



















Seems like this is a question about multer, and not about Azure Storage. Azure Storage doesn't generate random blob names; looks like this is the default behavior for multer when you don't specify a filename. Perhaps look at the multer DiskStorage documentation, which seems to cover it.

– David Makogon
Dec 28 '18 at 13:36







Seems like this is a question about multer, and not about Azure Storage. Azure Storage doesn't generate random blob names; looks like this is the default behavior for multer when you don't specify a filename. Perhaps look at the multer DiskStorage documentation, which seems to cover it.

– David Makogon
Dec 28 '18 at 13:36














1 Answer
1






active

oldest

votes


















1














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.



enter image description here



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() {
return '1.png';
}

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





share|improve this answer

























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53958935%2fproblem-in-uploading-image-in-azure-blob-storage%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    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.



    enter image description here



    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() {
    return '1.png';
    }

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





    share|improve this answer






























      1














      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.



      enter image description here



      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() {
      return '1.png';
      }

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





      share|improve this answer




























        1












        1








        1







        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.



        enter image description here



        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() {
        return '1.png';
        }

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





        share|improve this answer















        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.



        enter image description here



        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() {
        return '1.png';
        }

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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 31 '18 at 7:20

























        answered Dec 31 '18 at 7:14









        Peter PanPeter Pan

        10.9k3823




        10.9k3823






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53958935%2fproblem-in-uploading-image-in-azure-blob-storage%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Angular Downloading a file using contenturl with Basic Authentication

            Olmecas

            Can't read property showImagePicker of undefined in react native iOS