我想将使用“Microsoft.Azure.Storage.File”的方法重写为“Azure.Storage.Files.Shares”。此方法是使用 sasuri 将文件复制到文件共享。
/// <summary>
/// Data model for attachment content
/// </summary>
public class Attachment
{
/// <summary>
/// File Name
/// </summary>
public string FileName { get; set; }
/// <summary>
/// FileContent
/// </summary>
public string Content { get; set; }
/// <summary>
/// File Type
/// </summary>
public string ContentType { get; set; }
}
/// <summary>
/// CopyFileToShareAsync
/// </summary>
/// <param name="sasUri"></param>
/// <param name="attachment"></param>
/// <returns></returns>
public async Task CopyFileToShareAsync(string sasUri, Attachment attachment)
{
var cloudFileDirectory = new CloudFileDirectory(new Uri(sasUri));
var cloudFile = cloudFileDirectory.GetFileReference(attachment.FileName);
byte[] bytes = Convert.FromBase64String(attachment.Content);
await cloudFile.UploadFromStreamAsync(new MemoryStream(bytes));
}