[英]Encrypting image data before uploading to azure blob storage
我有以下代码将映像上传到Azure blob存储。 我想在上传到Blob之前对图像数据进行加密。 我已经有了一个用于加密和解密的助手类,可以通过调用AESEncryption.Encrypt(“ plainText”,“ key”,salt“);来使用。
我只是想弄清楚如何将加密方法集成到代码中。 另外,我猜想一旦将其加密而不是调用blob.UploadFromFile(),我将调用blob.UploadFromByteArray()。
public override Task ExecutePostProcessingAsync()
{
try
{
// Upload the files to azure blob storage and remove them from local disk
foreach (var fileData in this.FileData)
{
var filename = BuildFilename(Path.GetExtension(fileData.Headers.ContentDisposition.FileName.Trim('"')));
// Retrieve reference to a blob
var blob = _container.GetBlockBlobReference(filename);
blob.Properties.ContentType = fileData.Headers.ContentType.MediaType;
blob.UploadFromFile(fileData.LocalFileName, FileMode.Open);
File.Delete(fileData.LocalFileName);
Files.Add(new FileDetails
{
ContentType = blob.Properties.ContentType,
Name = blob.Name,
Size = blob.Properties.Length,
Location = blob.Uri.AbsoluteUri
});
}
}
catch (Exception ex)
{
throw ex;
}
return base.ExecutePostProcessingAsync();
}
如我所见,您可以通过3种方式做到这一点:
UploadFromByteArray
方法将其上传。 UploadFromStream
方法上传,而不是上传字节数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.