C# Azure blob stoarge上载文件需要更多时间
我正在使用azure blob存储上载文件。我使用了PutLock方法。但上传17MB的文件也需要2分钟。有没有办法用编程的方式快速上传文件 有没有办法用编程的方式快速上传文件 有一个专门用于高性能上传、下载和复制Azure存储Blob和文件的应用程序。为了快速上传blob,您可以使用它并遵循以下步骤 下面是一个代码示例,由我自己测试,将一个63MB的文件上载到azure blob存储大约需要25秒:C# Azure blob stoarge上载文件需要更多时间,c#,performance,azure-storage-blobs,C#,Performance,Azure Storage Blobs,我正在使用azure blob存储上载文件。我使用了PutLock方法。但上传17MB的文件也需要2分钟。有没有办法用编程的方式快速上传文件 有没有办法用编程的方式快速上传文件 有一个专门用于高性能上传、下载和复制Azure存储Blob和文件的应用程序。为了快速上传blob,您可以使用它并遵循以下步骤 下面是一个代码示例,由我自己测试,将一个63MB的文件上载到azure blob存储大约需要25秒: static void Main(string[] args)
static void Main(string[] args)
{
//use stop watch to calculate the uploading time.
Stopwatch stopwatch = Stopwatch.StartNew();
string storageConnectionString = "DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxxx;EndpointSuffix=core.windows.net";
CloudStorageAccount account = CloudStorageAccount.Parse(storageConnectionString);
CloudBlobClient blobClient = account.CreateCloudBlobClient();
CloudBlobContainer blobContainer = blobClient.GetContainerReference("test2");
blobContainer.CreateIfNotExists();
// the file being uploaded is about 63MB in size
string source_path = @"F:\temp\postman.zip";
CloudBlockBlob destBlob = blobContainer.GetBlockBlobReference("myblob111.zip");
TransferManager.Configurations.ParallelOperations = 5;
// Setup the transfer context and track the upload progress
SingleTransferContext context = new SingleTransferContext();
context.ProgressHandler = new Progress<TransferStatus>((progress) =>
{
Console.WriteLine("Bytes uploaded: {0}", progress.BytesTransferred);
});
// Upload a local blob
var task = TransferManager.UploadAsync(
source_path, destBlob, null, context, CancellationToken.None);
task.Wait();
stopwatch.Stop();
Console.WriteLine($"it takes about {stopwatch.ElapsedMilliseconds} milliSeconds");
Console.WriteLine("the upload is completed");
Console.ReadLine();
}
static void Main(字符串[]args)
{
//使用秒表计算上传时间。
秒表秒表=Stopwatch.StartNew();
string storageConnectionString=“DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxxx;EndpointSuffix=core.windows.net”;
CloudStorageAccount=CloudStorageAccount.Parse(storageConnectionString);
CloudBlobClient blobClient=account.CreateCloudBlobClient();
CloudBlobContainer blobContainer=blobClient.GetContainerReference(“test2”);
blobContainer.CreateIfNotExists();
//正在上载的文件大小约为63MB
字符串source_path=@“F:\temp\postman.zip”;
CloudBlockBlob destBlob=blobContainer.getblockblobbreference(“myblobb111.zip”);
TransferManager.Configurations.ParallelOperations=5;
//设置传输上下文并跟踪上载进度
SingleTransferContext=新的SingleTransferContext();
context.ProgressHandler=新进度((进度)=>
{
WriteLine(“上传的字节:{0}”,progress.ByTestTransfered);
});
//上载本地blob
var task=TransferManager.UploadAsync(
源路径,destBlob,null,上下文,CancellationToken.None);
task.Wait();
秒表;
WriteLine($“大约需要{stopwatch.elapsedmillisons}毫秒”);
Console.WriteLine(“上传完成”);
Console.ReadLine();
}
测试结果:
Hai,谢谢您的回复。我尝试了这个,我使用了这个代码进行上传。17 MB的上传需要2分钟以上。如果删除此行destBlob.Properties.ContentType=“image/jpeg”;它正在以50秒的速度快速上传。但我想上传这一行。我需要更改azure portal中的任何配置吗???请在这里找到我的代码@arulpushpam,我可以想出两种方法来设置ContentType。方法1。图像上载到blob存储后,可以使用,然后手动更改内容类型。方法2.上传图像后,可以使用代码获取并更改blob的内容类型属性。我无法手动更改图像内容类型。我在这里上传了很多文件。我没有使用代码检索附件。我正在使用azure路径获取附件。因此,在这里检索时无法更改内容类型。是否有新的上载方法fastly@arulpushpam,你介意分享大尺寸的图片吗?我没有17MB大小的图像。我还注意到,您首先以流的形式读取图像,然后上载流。为什么不直接上传图像而不使用流呢?在我这边,我不能发送源路径。所以为什么我把文件读成流呢。