我一直关注this example将大型文件从MVC网络应用程序上传到Azure blob存储块中。
在该示例中,第一个控制器操作创建blob引用并在Session中存储一些元数据:
var fileToUpload = new CloudFile()
{
BlockCount = blocksCount,
FileName = fileName,
Size = fileSize,
BlockBlob = container.GetBlockBlobReference(fileName),
StartTime = DateTime.Now,
IsUploadCompleted = false,
UploadStatusMessage = string.Empty
};
Session.Add("CurrentFile", fileToUpload);
允许每个连续的呼叫从中断的地方继续:
CloudFile model = (CloudFile)Session["CurrentFile"];
model.BlockBlob.PutBlock(*new chunk stream*);
很明显,这是为了方便本教程而做的,但对我来说应该如何完成并不明显。对于可扩展的云应用程序,我根本不想使用会话。
我的问题是,在每个块上传中简单地提交和重写blob存储是否完全没问题,如果没有,是否有适合Azure应用程序的缓存替代方案?
如果它影响答案,我想从javascript调用WebAPI控制器,所以无论如何都没有会话。
答案 0 :(得分:0)
你有几个选择。第一种方法是继续使用Session对象和change the Session Provider(见下文)。第二个是write your own layer that would handle caching给你一些像Redis这样的东西。无论哪种情况,currently recommended caching solution都是Redis。
对于第一个选项,有几个Session Providers available:
您可以继续使用Session对象并在Web.Config中切换Session Provider以使用Redis而不是内存。首先添加RedisSessionStateProvider Package from NuGet,然后更新web.config:
<sessionStatemode="Custom" customProvider="MySessionStateStore">
<providers>
<!--Remove old session state info if currently configured.-->
<add name="MySessionStateStore" type="Microsoft.Web.Redis.RedisSessionStateProvider" host="<redis host url/ip here>" accessKey="<your access key here>" />
</providers>
caching guidance in Azure Microsoft Patterns and Practices Team上的这篇文章提供了关于这两种情景的大量信息。