我有一个WCF服务作为WebRole的Windows Azure项目。 我在Azure中有一个存储帐户,我想在其上保存文件。Azure WCF服务在BLOB存储文件上给出错误
我的代码在我使用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;
}