简体   繁体   English

使用URL的Azure下载Blob

[英]Azure download blob using url

I have created an Azure Cloud Service project on Visual Studio. 我已经在Visual Studio上创建了一个Azure云服务项目。 I've been able to upload my files in the azure blob storage. 我已经能够将文件上传到azure blob存储中。 What i need is, when click on a button, it will return me the URL of the uploaded blob such as http://127.0.0.1:10000/devstoreaccount1/conversions/filename.extension 我需要的是,当单击按钮时,它将返回我上传的Blob的URL,例如http://127.0.0.1:10000/devstoreaccount1/conversions/filename.extension

In my View, i've done the following: 在我看来,我已经完成了以下工作:

 <div class="table"> <table class="table table-responsive"> <thead> <tr> <th>File Name</th> <th>ConversionID</th> <th>Actual Format</th> <th>Status</th> <th>Download</th> </tr> </thead> @foreach (var item in Model) { <tr> <td>@item.FileName</td> <td>@item.ConversionID</td> <td>@item.Format</td> <td>@item.Status</td> <td> <a href="/Download.aspx?conversionID=@item.ConversionID"> <span class="DownloadListItem"> <b>Download<b> </span> </a> </tr> } </table> </div> 

My Download.aspx.cs: 我的Download.aspx.cs:

    private ApplicationDbContext db = new ApplicationDbContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        string rawId = Request.QueryString["ConversionID"];
        int converionID;

        if (!String.IsNullOrEmpty(rawId) && int.TryParse(rawId, out converionID))
        {
          var v = db.Conversions.Where(a => a.ConversionID.Equals(converionID));  

            if (v != null)
            {
                //return ConversionURL
            }   
        }

        else
        {
            Debug.Fail("ERROR : We should never get to AddToCart.aspx without a ConversionID.");
            throw new Exception("ERROR : It is illegal to load AddToCart.aspx without setting a ConversionID.");
        }
    }

How can i return the ConversionURL in my code? 如何在代码中返回ConversionURL?

EDIT 编辑

When i upload a file, i upload the file and its content in Azure Blob Storage, but i also store on a SQL server database the ConversionID and ConversionURL of the uploaded file. 上载文件时,我将文件及其内容上载到Azure Blob存储中,但我还将SQL Server数据库中存储了上载文件的ConversionID和ConversionURL。

Once you upload your blob, you have the access to the Uri property of cloud blob . 一旦上传了Blob,您就可以访问cloud blobUri属性 Save that after your upload to the database and return once you gets the ConversionId. 将其上传到数据库后保存,并在获得ConversionId后返回。

        blob.UploadFromFile(...);
        var blobUrl = blob.Uri;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM