作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何从上次断开连接后恢复在 Azure 中的上传。在网络故障中我可以继续,但是当我的系统重新启动时断电后我必须做什么。我如何保存软件的当前状态(正在将文件上传到 Azure)。因此,如果我保存我的状态,我可以从上一点恢复它。我正在使用此代码进行上传。该代码来自互联网。
private void UploadBigFile(){
int count = 0, bufferSize = 40 * 1024, blockCount = 0;
string filePath = @"D:\Dua.zip";
List<string> blockIds = new List<string>();
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("mytestcontainer");
container.CreateIfNotExists();
byte[] bufferBytes = new byte[bufferSize];
string fileName = Path.GetFileName(filePath);
CloudBlockBlob blob = container.GetBlockBlobReference(fileName);
using (FileStream fileStream = File.OpenRead(filePath)){
blockCount = (int)(fileStream.Length / bufferSize) + 1;
Int64 currentBlockSize = 0;
int currentCount = blockIds.Count();
fileStream.Seek(bufferSize * currentCount, SeekOrigin.Begin);
for (int i = blockIds.Count; i < blockCount; i++){
currentBlockSize = bufferSize;
if (i == blockCount - 1){
currentBlockSize = fileStream.Length - bufferSize * i;
bufferBytes = new byte[currentBlockSize];
}
if (currentBlockSize == 0) break;
fileStream.Read(bufferBytes, 0, Convert.ToInt32(currentBlockSize));
using (MemoryStream memoryStream = new MemoryStream(bufferBytes)){
try{
string blockId = Convert.ToBase64String(Encoding.UTF8.GetBytes(Guid.NewGuid().ToString()));
blob.PutBlock(blockId, memoryStream, null);
blockIds.Add(blockId);
count++;
label1.Text = Convert.ToString(count);
label1.Refresh();
}
catch (Exception){}
}
}
}
blob.PutBlockList(blockIds);
}
最佳答案
如果您正在跟踪 block ,则可以保存位置,然后重新启动。这是一篇关于 uploading large files 的博客文章;它的结尾准确地告诉了如何做你想做的事情。
关于azure - 断电后使用 Azure 恢复上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32860726/
对于我正在构建的系统,我需要一个视频编解码器,它可以承受断电 - 即,如果断电,视频仍然需要从闪存盘上剩余的内容中播放。 (车载电脑项目,拔下 key 后电脑立即关闭,如果在事故中断电)。 谁能推荐合
是否可以创建一个逻辑应用来监视特定虚拟机并发送有关断电/通电或 CPU 使用率百分比的电子邮件通知? 我已经阅读了事件网格,但它似乎更适合资源创建/删除通知,而不是特定的虚拟机信号。 我也知道可以在虚
我是一名优秀的程序员,十分优秀!