How to add and retrive additional information for Azure Blob











up vote
0
down vote

favorite












Is there a way to add additional information for blob in Azure?



I want to store some relevant information, which connects the blob to other entity in in an a document database, for example a string which contains a JSON.



I know there is metadata for blob when I use Azure Storage explorer, but i want use it from code.



This a relevant question about this theme:
Adding Description/Metadata to Azure Blob



And how can retrieve the blobs based on this metadata?










share|improve this question




























    up vote
    0
    down vote

    favorite












    Is there a way to add additional information for blob in Azure?



    I want to store some relevant information, which connects the blob to other entity in in an a document database, for example a string which contains a JSON.



    I know there is metadata for blob when I use Azure Storage explorer, but i want use it from code.



    This a relevant question about this theme:
    Adding Description/Metadata to Azure Blob



    And how can retrieve the blobs based on this metadata?










    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Is there a way to add additional information for blob in Azure?



      I want to store some relevant information, which connects the blob to other entity in in an a document database, for example a string which contains a JSON.



      I know there is metadata for blob when I use Azure Storage explorer, but i want use it from code.



      This a relevant question about this theme:
      Adding Description/Metadata to Azure Blob



      And how can retrieve the blobs based on this metadata?










      share|improve this question















      Is there a way to add additional information for blob in Azure?



      I want to store some relevant information, which connects the blob to other entity in in an a document database, for example a string which contains a JSON.



      I know there is metadata for blob when I use Azure Storage explorer, but i want use it from code.



      This a relevant question about this theme:
      Adding Description/Metadata to Azure Blob



      And how can retrieve the blobs based on this metadata?







      c# .net azure blob azure-storage






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 at 19:04

























      asked Nov 19 at 7:18









      György Gulyás

      21618




      21618
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          4
          down vote













          Have you checked this link?



          public static async Task AddContainerMetadataAsync(CloudBlobContainer container)
          {
          // Add some metadata to the container.
          container.Metadata.Add("docType", "textDocuments");
          container.Metadata["category"] = "guidance";

          // Set the container's metadata.
          await container.SetMetadataAsync();
          }


          Keep in mind that




          The name of your metadata must conform to the naming conventions for C# identifiers.







          share|improve this answer





















          • That's it! Thank you.
            – György Gulyás
            Nov 19 at 7:57










          • Is there a way to listing this blobs based on metadata content?
            – György Gulyás
            Nov 19 at 8:02










          • Maybe this will help: Azure Search. I haven't tried it yet. I usually get them by the default index and then display the metadata.
            – Mihail Stancescu
            Nov 19 at 8:07










          • thx, it will help. In other way, but helps. :) Thx lot!
            – György Gulyás
            Nov 19 at 8:40


















          up vote
          -1
          down vote













          The first part of the question is answered by Mihail Stancescu, thank you!



          The second part is not answered correctly yet. The Azure Search is a solution for it, but it is a totally other service. I want to solve this problem in my repository class. And i solved it.



          Maybe it is interesting for someone else that is why I share my solution:



          public IEnumerable<T> GetMany( Expression<Func<T, bool>> filter )
          {
          return _AzureBlobCollection.BlobDirectory
          .ListBlobs( useFlatBlobListing: false, blobListingDetails: Microsoft.WindowsAzure.Storage.Blob.BlobListingDetails.Metadata )
          .OfType<Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob>()
          .Select<Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob, T>( blob => JsonConvert.DeserializeObject<T>( blob.Metadata[ "data" ] ) )
          .Where( filter.Compile() );
          }


          This function can call like this:
          Repository repository = ..



          IEnumerable files = repository.GetMany( f => f.Partner = "Microsoft" );


          where file class is:



          public class ContractFile : File
          {
          public string Partner { get; set; }
          public Date CreationDate { get; set; }
          public string Remarks { get; set; }
          public string Filename { get; set; }
          }
          ...
          public class File
          {
          public String File { get; set; }
          public Stream Data { get; set; }
          }


          And the insert is following:



              public void AddOne( T file )
          {
          file.id = Guid.NewGuid().ToString();
          Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blob = _AzureBlobCollection.BlobDirectory.GetBlockBlobReference( file.id );

          blob.UploadFromStream( file.Data );
          blob.Metadata.Add( "data", JsonConvert.SerializeObject( file ) );
          blob.SetMetadata();
          }





          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',
            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%2f53369937%2fhow-to-add-and-retrive-additional-information-for-azure-blob%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            4
            down vote













            Have you checked this link?



            public static async Task AddContainerMetadataAsync(CloudBlobContainer container)
            {
            // Add some metadata to the container.
            container.Metadata.Add("docType", "textDocuments");
            container.Metadata["category"] = "guidance";

            // Set the container's metadata.
            await container.SetMetadataAsync();
            }


            Keep in mind that




            The name of your metadata must conform to the naming conventions for C# identifiers.







            share|improve this answer





















            • That's it! Thank you.
              – György Gulyás
              Nov 19 at 7:57










            • Is there a way to listing this blobs based on metadata content?
              – György Gulyás
              Nov 19 at 8:02










            • Maybe this will help: Azure Search. I haven't tried it yet. I usually get them by the default index and then display the metadata.
              – Mihail Stancescu
              Nov 19 at 8:07










            • thx, it will help. In other way, but helps. :) Thx lot!
              – György Gulyás
              Nov 19 at 8:40















            up vote
            4
            down vote













            Have you checked this link?



            public static async Task AddContainerMetadataAsync(CloudBlobContainer container)
            {
            // Add some metadata to the container.
            container.Metadata.Add("docType", "textDocuments");
            container.Metadata["category"] = "guidance";

            // Set the container's metadata.
            await container.SetMetadataAsync();
            }


            Keep in mind that




            The name of your metadata must conform to the naming conventions for C# identifiers.







            share|improve this answer





















            • That's it! Thank you.
              – György Gulyás
              Nov 19 at 7:57










            • Is there a way to listing this blobs based on metadata content?
              – György Gulyás
              Nov 19 at 8:02










            • Maybe this will help: Azure Search. I haven't tried it yet. I usually get them by the default index and then display the metadata.
              – Mihail Stancescu
              Nov 19 at 8:07










            • thx, it will help. In other way, but helps. :) Thx lot!
              – György Gulyás
              Nov 19 at 8:40













            up vote
            4
            down vote










            up vote
            4
            down vote









            Have you checked this link?



            public static async Task AddContainerMetadataAsync(CloudBlobContainer container)
            {
            // Add some metadata to the container.
            container.Metadata.Add("docType", "textDocuments");
            container.Metadata["category"] = "guidance";

            // Set the container's metadata.
            await container.SetMetadataAsync();
            }


            Keep in mind that




            The name of your metadata must conform to the naming conventions for C# identifiers.







            share|improve this answer












            Have you checked this link?



            public static async Task AddContainerMetadataAsync(CloudBlobContainer container)
            {
            // Add some metadata to the container.
            container.Metadata.Add("docType", "textDocuments");
            container.Metadata["category"] = "guidance";

            // Set the container's metadata.
            await container.SetMetadataAsync();
            }


            Keep in mind that




            The name of your metadata must conform to the naming conventions for C# identifiers.








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 19 at 7:25









            Mihail Stancescu

            3,33911018




            3,33911018












            • That's it! Thank you.
              – György Gulyás
              Nov 19 at 7:57










            • Is there a way to listing this blobs based on metadata content?
              – György Gulyás
              Nov 19 at 8:02










            • Maybe this will help: Azure Search. I haven't tried it yet. I usually get them by the default index and then display the metadata.
              – Mihail Stancescu
              Nov 19 at 8:07










            • thx, it will help. In other way, but helps. :) Thx lot!
              – György Gulyás
              Nov 19 at 8:40


















            • That's it! Thank you.
              – György Gulyás
              Nov 19 at 7:57










            • Is there a way to listing this blobs based on metadata content?
              – György Gulyás
              Nov 19 at 8:02










            • Maybe this will help: Azure Search. I haven't tried it yet. I usually get them by the default index and then display the metadata.
              – Mihail Stancescu
              Nov 19 at 8:07










            • thx, it will help. In other way, but helps. :) Thx lot!
              – György Gulyás
              Nov 19 at 8:40
















            That's it! Thank you.
            – György Gulyás
            Nov 19 at 7:57




            That's it! Thank you.
            – György Gulyás
            Nov 19 at 7:57












            Is there a way to listing this blobs based on metadata content?
            – György Gulyás
            Nov 19 at 8:02




            Is there a way to listing this blobs based on metadata content?
            – György Gulyás
            Nov 19 at 8:02












            Maybe this will help: Azure Search. I haven't tried it yet. I usually get them by the default index and then display the metadata.
            – Mihail Stancescu
            Nov 19 at 8:07




            Maybe this will help: Azure Search. I haven't tried it yet. I usually get them by the default index and then display the metadata.
            – Mihail Stancescu
            Nov 19 at 8:07












            thx, it will help. In other way, but helps. :) Thx lot!
            – György Gulyás
            Nov 19 at 8:40




            thx, it will help. In other way, but helps. :) Thx lot!
            – György Gulyás
            Nov 19 at 8:40












            up vote
            -1
            down vote













            The first part of the question is answered by Mihail Stancescu, thank you!



            The second part is not answered correctly yet. The Azure Search is a solution for it, but it is a totally other service. I want to solve this problem in my repository class. And i solved it.



            Maybe it is interesting for someone else that is why I share my solution:



            public IEnumerable<T> GetMany( Expression<Func<T, bool>> filter )
            {
            return _AzureBlobCollection.BlobDirectory
            .ListBlobs( useFlatBlobListing: false, blobListingDetails: Microsoft.WindowsAzure.Storage.Blob.BlobListingDetails.Metadata )
            .OfType<Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob>()
            .Select<Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob, T>( blob => JsonConvert.DeserializeObject<T>( blob.Metadata[ "data" ] ) )
            .Where( filter.Compile() );
            }


            This function can call like this:
            Repository repository = ..



            IEnumerable files = repository.GetMany( f => f.Partner = "Microsoft" );


            where file class is:



            public class ContractFile : File
            {
            public string Partner { get; set; }
            public Date CreationDate { get; set; }
            public string Remarks { get; set; }
            public string Filename { get; set; }
            }
            ...
            public class File
            {
            public String File { get; set; }
            public Stream Data { get; set; }
            }


            And the insert is following:



                public void AddOne( T file )
            {
            file.id = Guid.NewGuid().ToString();
            Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blob = _AzureBlobCollection.BlobDirectory.GetBlockBlobReference( file.id );

            blob.UploadFromStream( file.Data );
            blob.Metadata.Add( "data", JsonConvert.SerializeObject( file ) );
            blob.SetMetadata();
            }





            share|improve this answer

























              up vote
              -1
              down vote













              The first part of the question is answered by Mihail Stancescu, thank you!



              The second part is not answered correctly yet. The Azure Search is a solution for it, but it is a totally other service. I want to solve this problem in my repository class. And i solved it.



              Maybe it is interesting for someone else that is why I share my solution:



              public IEnumerable<T> GetMany( Expression<Func<T, bool>> filter )
              {
              return _AzureBlobCollection.BlobDirectory
              .ListBlobs( useFlatBlobListing: false, blobListingDetails: Microsoft.WindowsAzure.Storage.Blob.BlobListingDetails.Metadata )
              .OfType<Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob>()
              .Select<Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob, T>( blob => JsonConvert.DeserializeObject<T>( blob.Metadata[ "data" ] ) )
              .Where( filter.Compile() );
              }


              This function can call like this:
              Repository repository = ..



              IEnumerable files = repository.GetMany( f => f.Partner = "Microsoft" );


              where file class is:



              public class ContractFile : File
              {
              public string Partner { get; set; }
              public Date CreationDate { get; set; }
              public string Remarks { get; set; }
              public string Filename { get; set; }
              }
              ...
              public class File
              {
              public String File { get; set; }
              public Stream Data { get; set; }
              }


              And the insert is following:



                  public void AddOne( T file )
              {
              file.id = Guid.NewGuid().ToString();
              Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blob = _AzureBlobCollection.BlobDirectory.GetBlockBlobReference( file.id );

              blob.UploadFromStream( file.Data );
              blob.Metadata.Add( "data", JsonConvert.SerializeObject( file ) );
              blob.SetMetadata();
              }





              share|improve this answer























                up vote
                -1
                down vote










                up vote
                -1
                down vote









                The first part of the question is answered by Mihail Stancescu, thank you!



                The second part is not answered correctly yet. The Azure Search is a solution for it, but it is a totally other service. I want to solve this problem in my repository class. And i solved it.



                Maybe it is interesting for someone else that is why I share my solution:



                public IEnumerable<T> GetMany( Expression<Func<T, bool>> filter )
                {
                return _AzureBlobCollection.BlobDirectory
                .ListBlobs( useFlatBlobListing: false, blobListingDetails: Microsoft.WindowsAzure.Storage.Blob.BlobListingDetails.Metadata )
                .OfType<Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob>()
                .Select<Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob, T>( blob => JsonConvert.DeserializeObject<T>( blob.Metadata[ "data" ] ) )
                .Where( filter.Compile() );
                }


                This function can call like this:
                Repository repository = ..



                IEnumerable files = repository.GetMany( f => f.Partner = "Microsoft" );


                where file class is:



                public class ContractFile : File
                {
                public string Partner { get; set; }
                public Date CreationDate { get; set; }
                public string Remarks { get; set; }
                public string Filename { get; set; }
                }
                ...
                public class File
                {
                public String File { get; set; }
                public Stream Data { get; set; }
                }


                And the insert is following:



                    public void AddOne( T file )
                {
                file.id = Guid.NewGuid().ToString();
                Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blob = _AzureBlobCollection.BlobDirectory.GetBlockBlobReference( file.id );

                blob.UploadFromStream( file.Data );
                blob.Metadata.Add( "data", JsonConvert.SerializeObject( file ) );
                blob.SetMetadata();
                }





                share|improve this answer












                The first part of the question is answered by Mihail Stancescu, thank you!



                The second part is not answered correctly yet. The Azure Search is a solution for it, but it is a totally other service. I want to solve this problem in my repository class. And i solved it.



                Maybe it is interesting for someone else that is why I share my solution:



                public IEnumerable<T> GetMany( Expression<Func<T, bool>> filter )
                {
                return _AzureBlobCollection.BlobDirectory
                .ListBlobs( useFlatBlobListing: false, blobListingDetails: Microsoft.WindowsAzure.Storage.Blob.BlobListingDetails.Metadata )
                .OfType<Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob>()
                .Select<Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob, T>( blob => JsonConvert.DeserializeObject<T>( blob.Metadata[ "data" ] ) )
                .Where( filter.Compile() );
                }


                This function can call like this:
                Repository repository = ..



                IEnumerable files = repository.GetMany( f => f.Partner = "Microsoft" );


                where file class is:



                public class ContractFile : File
                {
                public string Partner { get; set; }
                public Date CreationDate { get; set; }
                public string Remarks { get; set; }
                public string Filename { get; set; }
                }
                ...
                public class File
                {
                public String File { get; set; }
                public Stream Data { get; set; }
                }


                And the insert is following:



                    public void AddOne( T file )
                {
                file.id = Guid.NewGuid().ToString();
                Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blob = _AzureBlobCollection.BlobDirectory.GetBlockBlobReference( file.id );

                blob.UploadFromStream( file.Data );
                blob.Metadata.Add( "data", JsonConvert.SerializeObject( file ) );
                blob.SetMetadata();
                }






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 at 16:13









                György Gulyás

                21618




                21618






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369937%2fhow-to-add-and-retrive-additional-information-for-azure-blob%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

                    Costa Masnaga

                    Fotorealismo

                    Sidney Franklin