我有一个带有 WCF 服务作为 WebRole 的 Windows Azure 项目。我在 Azure 中有一个存储帐户,我想在其中保存文件。
我的代码在我使用 Azure 模拟器进行测试时工作。
但知道我得到了下一个错误:
Could not find a part of the path 'C:\temp\BatchAzure.log'.
客户端我正在尝试执行的服务:
string path = @"C:\temp\BatchAzure.log";
var test = service.SaveGezichtBestand(path, "999999");
我正在使用的方法:
public bool SaveGezichtBestand(string filePath, string memberID)
{
bool result = false;
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container
CloudBlobContainer container = blobClient.GetContainerReference("facefileblobcontainer");
// Create the container if it doesn't already exist
container.CreateIfNotExist();
//By default, the new container is private, so you must specify your storage account key (as you did above)
//to download blobs from this container.
container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
// Retrieve reference to a blob named "myblob"
CloudBlob blob = container.GetBlobReference(memberID);
try
{
// Create or overwrite the "myblob" blob with contents from a local file
using (var fileStream = System.IO.File.OpenRead(filePath))
{
blob.UploadFromStream(fileStream);
result = true;
}
}
catch (Exception)
{
result = false;
throw;
}
return result;
}