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?
c# .net azure blob azure-storage
add a comment |
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?
c# .net azure blob azure-storage
add a comment |
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?
c# .net azure blob azure-storage
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
c# .net azure blob azure-storage
edited Nov 23 at 19:04
asked Nov 19 at 7:18
György Gulyás
21618
21618
add a comment |
add a comment |
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.
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
add a comment |
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();
}
add a comment |
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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();
}
add a comment |
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();
}
add a comment |
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();
}
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();
}
answered Nov 23 at 16:13
György Gulyás
21618
21618
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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