0
我有一个XDocument作为参数提供,需要压缩并上传到Azure文件存储。这里有一些问题部分地回答了这个问题,但是对于blob存储。签名是不同的,我不能让它适用于我的情况,没有在云中获取压缩文件的校验和错误。在内存中压缩XML文件并将其上传到azure文件存储
public static bool ZipAndUploadDocumentToAzure(XDocument doc, Configuration config)
{
if (IsNullOrEmpty(config.StorageAccountName) ||
IsNullOrEmpty(config.StorageAccountKey) ||
IsNullOrEmpty(config.StorageAccounyShareReference) ||
IsNullOrEmpty(config.StorageAccounyDirectoryReference))
{
return false;
}
CloudStorageAccount storageAccount = CloudStorageAccount.Parse($"DefaultEndpointsProtocol=https;AccountName={config.StorageAccountName};AccountKey={config.StorageAccountKey}");
CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
CloudFileShare share = fileClient.GetShareReference(config.StorageAccounyShareReference);
CloudFileDirectory root = share.GetRootDirectoryReference();
CloudFileDirectory dir = root.GetDirectoryReference(config.StorageAccounyDirectoryReference);
var cloudFile = dir.GetFileReference("myarchive.zip");
using (var stream = new MemoryStream())
{
var xws = new XmlWriterSettings
{
OmitXmlDeclaration = true,
Indent = true
};
using (XmlWriter xw = XmlWriter.Create(stream, xws))
{
doc.WriteTo(xw);
}
//where to actually use ZipArchive 'using block' without saving
//any of the zip or XML or XDocument files locally
//and that it doesn't produce checksum error
cloudFile.UploadFromStream(stream);//this gives me XML file
//saved to file storage
return true;
}
}
谢谢!那做了这个工作。 –