我有一個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;
}