我在Visual Studio上创建了一个Azure云服务项目。我已经能够在 Azure Blob 存储中上传我的文件。我需要的是,当单击按钮时,它将向我返回上传的 blob 的 URL,例如 http://127.0.0.1:10000/devstoreaccount1/conversions/filename.extension
在我看来,我已经做到了以下几点:
<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>
我的下载.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.");
}
}
如何在代码中返回转化网址?
编辑
上传文件时,我会在 Azure Blob 存储中上传文件及其内容,但我也会在 SQL Server 数据库中存储上传文件的转换 ID 和转换 URL。
上传 Blob 后,即可访问云 Blob 的 Uri 属性。在上传到数据库后将其保存,并在获得转化 ID 后返回。
blob.UploadFromFile(...);
var blobUrl = blob.Uri;