locked
Retrieving an image stored in xdrive. RRS feed

  • Question

  • Hi,

    How we can retrieve the image stored in xdrive.I need to retrieve it and show it in other page.

     

    Thanks

    anuaj

     

     

    Tuesday, September 14, 2010 5:39 AM

Answers

  • Hi,

    So it's not a Azure issue. Firstly the ASP.NET Image control will render <img> for your browser to access resource. If the src of <img> is set to something like "a:\\yourimgpath\img.jpg" the browser will try to find the file from client machine. If it cannot find the image on client machine it cannot show the image. As a result, you need to specify a URL like http://yourserver/imghandler.aspx?imgid=xxx. In the aspx code behind (or, you may write your own HttpHandler), retrieve the imgid from query string and send back the image and the correct HTTP Header, such as Content-Type. You may refer to:

    http://msdn.microsoft.com/en-us/library/ms972953.aspx 

    to learn how to do so.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Windows Azure Platform China Blog: http://blogs.msdn.com/azchina/default.aspx
    Friday, September 24, 2010 9:50 AM

All replies

  • If you need to concurrently retrieve the image from xdrive while it is mounted for write operation elsewhere, you could use snapshot functionality to create read-only version of drive and read it from multiple role instances. Otherwise, you can mount the drive and perform the read operation.
    Please mark it as answer by clicking on "Propose As Answer", if it helps
    Tuesday, September 14, 2010 12:04 PM
  • hi Anuaj

    You may interest on this POST by Thomas Conte's Webblog.

    Hope it can help you.


    Believing is Seeing
    • Edited by Cybertron2008 Wednesday, September 15, 2010 3:03 AM Worng name
    Wednesday, September 15, 2010 3:02 AM
  • Hi Rajesh,

     

    Thanks for the reply.I am able to store it.But i need to get the path and display it in some other page.Now i am able to store it in driveletter a:\\.Is it possible to store somewhere else like D:\\ drive.How can i change the code to achieve this.pls give some sample code.My code is below:

     CloudStorageAccount storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
                LocalResource localCache = RoleEnvironment.GetLocalResource("InstanceDriveCache");
                CloudDrive.InitializeCache(localCache.RootPath, localCache.MaximumSizeInMegabytes);
                // Just checking: make sure the container exists
                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                blobClient.GetContainerReference("reports").CreateIfNotExist();
                CloudDrive myCloudDrive = storageAccount.CreateCloudDrive(
                    blobClient
                    .GetContainerReference("reports")
                    .GetPageBlobReference("reports.vhd")
                    .Uri.ToString()
                );

                try
                {
                    //myCloudDrive.Delete();
                    myCloudDrive.Create(64);
                }
                catch (CloudDriveException ex)
                {
                    // handle exception here
                    // exception is also thrown if all is well but the drive already exists
                }
                string driveLetter = myCloudDrive.Mount(25, DriveMountOptions.Force);
                string blobname = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
                FileUpload1.SaveAs(driveLetter + "\\" + blobname);
                string path = string.Concat(driveLetter,  FileUpload1.PostedFile.FileName);

    Please give some solution.

     

    Thanks

    anuaj

     

    Wednesday, September 15, 2010 4:54 AM
  • Hi Anuaj,

    To the best of my knowledge, the drive letter for an Azure drive is assigned to you. One thing you could do is save that path variable in shared scope and use that in other pages. Another thing you might want to think about is that these files are only accessible to your roles so if you want to display the contents of this file in some other page, you would need to read that file and stream the contents of that file. Another alternative would be to upload this file as block blob so that you can stream it to the clients.

    Hope this helps.

    Thanks

    Gaurav Mantri

    Cerebrata Software

    http://www.cerebrata.com

     

    Wednesday, September 15, 2010 5:02 AM
  • Anuaj,

    As you might already know, Drive letters are automatically generated upon mount operation. If your write operations are completed in this page, you could unmount from this page and mount it again in other page or application in which case you may get a different drive letter. As long as you use the drive letter returned from mount operation, you may not need to worry about what value it might get.


    Please mark it as answer by clicking on "Propose As Answer", if it helps
    Wednesday, September 15, 2010 5:08 AM
  • Hi Rajesh,

    I need to assign the path to some image control.So the image control won't accept a:\\ drive path.I cant give any response.redirect(filepath).It is a local path.Pleae give some solution.

     

    Thanks

    anuaj

    Wednesday, September 15, 2010 5:18 AM
  • Hi Anuaj,

    I don't think it is possible to do what you're looking to achieve. Basically an Azure drive is visible to your roles only. For an outsider (your image control for example) it would not be visible. One way to achieve what you're trying to do is read the contents of this file through your code and upload that file as block blob. You will then get a URI for the blob which you can refer in your image control.

    Hope this helps.

    Thanks

    Gaurav

    Wednesday, September 15, 2010 5:22 AM
  • Hi Gaurav,

     

    Thanks for the reply.Can we get the path(Xdrive path) where the uploaded content is stored.What  line of code should i write for that?

     

    Thanks

    Anuaj

    Wednesday, September 15, 2010 5:36 AM
  • Hi Anuaj,

    That would be the following statement from your code above:

    string path = string.Concat(driveLetter,  FileUpload1.PostedFile.FileName);

    However you may want to reconsider the choice of blob type. Basically you may want to use Page blobs (or Azure drive) is there are multiple read/writes to a file is desired and you may want to use Block blobs for streaming purposes (if you need to send something back to the client e.g. image files etc.)

    Hope this helps.

    Thanks

    Gaurav

    Wednesday, September 15, 2010 6:13 AM
  • Hi Gaurav,

     

    Thanks for the reply.If i store it in X drive i should be able to retrieve it.How i will take this a:\\ drive path,it is not coming under the local sytem.

     

    Thanks

    anuaj

    Wednesday, September 15, 2010 7:49 AM
  • Hi,

    Firstly we cannot control the driveletter beforehand. So changing the "a:\\" is impossible. To resolve the problem we could only start from another part of the problem:

    >I need to assign the path to some image control.So the image control won't accept a:\\ drive path

    If you could provide more details about the image control, i.e. why it won't accept a:\\ drive path, I'd be glad to provide some suggestions to get it work. If you mean the built-in ASP.NET Image control, you may write an HttpHandler to render images.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Windows Azure Platform China Blog: http://blogs.msdn.com/azchina/default.aspx
    Thursday, September 23, 2010 6:55 AM
  • Hi,

    I need to use the asp.net image control.a:\\ drive is not available in my system.So cannot give the path.If it is c:\\ or d:\\,i can.Please give some solution

    Thanks

    anuaj

    Friday, September 24, 2010 8:41 AM
  • Hi,

    So it's not a Azure issue. Firstly the ASP.NET Image control will render <img> for your browser to access resource. If the src of <img> is set to something like "a:\\yourimgpath\img.jpg" the browser will try to find the file from client machine. If it cannot find the image on client machine it cannot show the image. As a result, you need to specify a URL like http://yourserver/imghandler.aspx?imgid=xxx. In the aspx code behind (or, you may write your own HttpHandler), retrieve the imgid from query string and send back the image and the correct HTTP Header, such as Content-Type. You may refer to:

    http://msdn.microsoft.com/en-us/library/ms972953.aspx 

    to learn how to do so.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help. Windows Azure Platform China Blog: http://blogs.msdn.com/azchina/default.aspx
    Friday, September 24, 2010 9:50 AM