我有这个示例代码,通过单击按钮手动从数据库表中下载图像。
在Html页面中:
<asp:Button ID="Button1" runat="server" Text="Convert Byte to All Image " OnClick="Button1_Click" />
代码背后:
protected void Button1_Click(object sender, EventArgs e)
{
string sConn = ConfigurationManager.ConnectionStrings["conString"].ToString();
SqlConnection objConn = new SqlConnection(sConn);
objConn.Open();
string sTSQL = "Select TOP 1500 FileData, FileValue from Demo_Tbl where Active=1 and FileGroup='C_Photo'";
SqlCommand objCmd = new SqlCommand(sTSQL, objConn);
objCmd.CommandType = CommandType.Text;
SqlDataAdapter adapter = new SqlDataAdapter();
DataTable dt = new DataTable();
adapter.SelectCommand = objCmd;
adapter.SelectCommand.CommandTimeout = 10000;
adapter.Fill(dt);
objConn.Close();
for (int i = 0; i < dt.Rows.Count; i++)
{
string FileValue = dt.Rows[i]["FileValue"].ToString();
object FileData = dt.Rows[i]["FileData"];
System.IO.File.WriteAllBytes(Server.MapPath("/Images/" + FileValue), (byte[])FileData);
}
Response.Write("Images has been fetched");
}
我希望每次更新 Demo_Tbl 表时自动执行此下载。另外,我想要云数据库(https.clode.azure.com)blobs中的下载目标文件夹。
我需要一些人来帮助我,因为我很少知道。
答案 0 :(得分:0)
是的,下载更新活动是一个好主意。
如果您在更新事件上编写下载代码,则需要在更新事件完成之前等待下载方法。我建议您将队列消息插入Azure存储队列,然后使用Azure webjob QueueTrigger将文件下载到Azure Blob。 Here是一种使用Azure Webjob QueueTrigger调整图像大小的类似方案。我认为这对您的方案有所帮助。