C#上传IList 到一个天蓝色的斑点
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了C#上传IList 到一个天蓝色的斑点相关的知识,希望对你有一定的参考价值。
我想上传一个IFormFILe
列表,我将它们更改为流列表文件可以在一个上传?
答案
这是我用来在Azure Blob中上传文件的内容:
public interface IFileStorageService
{
Task<string> UploadImageAsync(IFormFile imageFile);
Task<string> UploadVideoAsync(IFormFile videoFile);
}
public class FileStorageService : IFileStorageService
{
private readonly Uri _baseUri = new Uri("YourBlobUrl");
private readonly CloudBlobClient _client;
public FileStorageService()
{
_client = new CloudBlobClient(_baseUri, new StorageCredentials("accoutName", "YourSecretKey"));
}
public async Task<string> UploadImageAsync(IFormFile imageFile)
{
try
{
StreamReader streamReader = new StreamReader(imageFile.OpenReadStream());
var container = _client.GetContainerReference("images");
var blob = container.GetBlockBlobReference(imageFile.FileName +".jpg");
await blob.UploadFromStreamAsync(streamReader.BaseStream);
return new Uri(_baseUri, $"/images/{imageFile.FileName}.jpg").ToString();
}
catch (Exception exception)
{
throw;
}
}
public async Task<string> UploadVideoAsync(IFormFile videoFile)
{
try
{
StreamReader videoStream = new StreamReader(videoFile.OpenReadStream());
var container = _client.GetContainerReference("videos");
var blob = container.GetBlockBlobReference(videoFile.FileName+".mp4");
await blob.UploadFromStreamAsync(videoStream.BaseStream);
return new Uri(_baseUri, $"/videos/{videoFile.FileName}.mp4").ToString();
}
catch (Exception exception)
{
throw;
}
}
}
现在你可以通过迭代IFormFile
列表来上传IFormFile
列表。
以上是关于C#上传IList 到一个天蓝色的斑点的主要内容,如果未能解决你的问题,请参考以下文章
优化算法斑点鬣狗优化算法(SHO)含Matlab源码 1463期