This is a migrated thread and some comments may be shown as answers.

Get image from zure storage

1 Answer 176 Views
CardView
This is a migrated thread and some comments may be shown as answers.
Az
Top achievements
Rank 1
Az asked on 15 Feb 2020, 04:43 AM

I am trying to achieve a similar experience as in your CardView demo with the cities. The images are stored as block blobs in an Azure storage account. The blobs have tags, which i want to expose , similar to the meta from the demo where we have city name, population, country).

As far as i saw, there is no direct integration for CloudBlockBlob, so i am trying to place this in a byte array in order to display. Yet the outcome is an empty box in the grid, for each item from the container. the blobs are correctly downloaded, verified by writing the fileContent byte array to disk via filestream.

Any idea on how to achieve this?

 

Thank you!

 

 public partial class Form1 : Form
    {
        string sasToken = "?st=2020-02-12T21%3A05%3A08Z&se=2021-02-13T21%3A05%3A00Z&sp=rl&sv=2018-03-28&sr=c&sig=*redacted*";
        public Form1()
        {
            InitializeComponent();
            
        }


        public List<IListBlobItem> MainBody3(string id)
        {
            StorageCredentials accountSAS = new StorageCredentials(sasToken);

            // Use these credentials and the account name to create a Blob service client.
            CloudStorageAccount account = new CloudStorageAccount(accountSAS, "storage_account_name", endpointSuffix: null, useHttps: true);

            CloudBlobClient client = account.CreateCloudBlobClient();
            CloudBlobContainer container = client.GetContainerReference("images-analyzed-sampled");

            BlobContinuationToken token = null;
            List<BlobInfo> blobi = new List<BlobInfo>();
            List<IListBlobItem> poze = new List<IListBlobItem>();
            BlobRequestOptions options = new BlobRequestOptions();
            var myResults = new DataSet();
            do
            {
                var result = container.ListBlobsSegmented(null, true, new BlobListingDetails(), 20, token, null, null);
                token = result.ContinuationToken;

                var blobs = result.Results;
                foreach (IListBlobItem item in blobs)
                {
                    var blob = item as CloudBlockBlob;

                    long fileByteLength = blob.Properties.Length;
                    byte[] fileContent = new byte[fileByteLength];
                    for (int i = 0; i < fileByteLength; i++)
                    {
                        fileContent[i] = 0x20;
                    }
                   
                    radCardView1.Items.Add(blob.DownloadToByteArray(fileContent, 0));

                }
            } while (token != null);


            return poze;

        }




        private bool HasMatchingMetadata(CloudBlockBlob blob, string term)
        {
            foreach (var item in blob.Metadata)
            {
                if (((item.Key.StartsWith("Tag") || (item.Key.StartsWith("PredictedImageType"))) && item.Value.Equals(term, StringComparison.InvariantCultureIgnoreCase)))
                    return true;
            }

            return false;
        }

        private void radButton1_Click(object sender, EventArgs e)
        {
            MainBody3("");
        }
    }
    public class BlobInfo
    {
        public string ImageUri { get; set; }
        public string ThumbnailUri { get; set; }
        public string Caption { get; set; }
    }
}

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 19 Feb 2020, 01:46 PM

Hello,

According to the provided information, it seems that you download your images from the cloud and you want to use them in RadCardView. I would like to note that it is necessary to have the images locally on your machine before applying them to card view. Then, you can store the image path. Note that RadCardView.Items collection expects ListViewDataItems to be added, not the image itself. Take a look at the following help article: https://docs.telerik.com/devtools/winforms/controls/cardview/populating-with-data/unbound-mode#adding-items-and-populating-cells.

In the CardViewItemFormatting event, you can get the image by the specified file path and assign it to CardViewItem. For your reference, I created a sample project demonstrating how you can set an image by using an image path. Could you please check it and see how it works.

I hope this helps. Let me know if I can assist you further.

Regards,
Nadya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
CardView
Asked by
Az
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or