Am stuck with this error The specified container does not exist.
我遇到了这个错误指定的容器不存在。
let me explain,
让我解释,
CloudBlobClient blobStorage = GetBlobStorage("upload");
CloudBlockBlob blob = BlobPropertySetting(blobStorage, Guid.NewGuid().ToString().ToLower() + Path.GetExtension(file.FileName));
blob.UploadFromStream(file.InputStream);
public static CloudBlobClient GetBlobStorage(string cloudBlobContainserName)
{
CloudBlobClient blobStorage;
try
{
var storageAccount = CloudStorageAccount.FromConfigurationSetting("StorageConnectionString");
blobStorage = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobStorage.GetContainerReference(cloudBlobContainserName);
container.CreateIfNotExist();
var permissions = container.GetPermissions();
permissions.PublicAccess = BlobContainerPublicAccessType.Container;
container.SetPermissions(permissions);
}
catch (Exception ex)
{
Logger.LogError(Log4NetLogger.Category.Exception, "Error in : BlobHandler.GetBlobStorage :>> Exception message: " + ex.Message);
throw;
}
return blobStorage;
}
public static CloudBlockBlob BlobPropertySetting(CloudBlobClient cloudBlobClientReferenceName, string blobContentName)
{
CloudBlockBlob blob = cloudBlobClientReferenceName.GetBlockBlobReference(blobContentName);
return blob;
}
and my StorageConnectionString
is
我的StorageConnectionString是
<Setting name="StorageConnectionString" value="DefaultEndpointsProtocol=https;AccountName=duw;AccountKey=bla bla" />
container 'upload' and the storage account 'duw' exist.
容器'上传'和存储帐户'duw'存在。
executing blob.UploadFromStream(file.InputStream);
statement causes the error.
执行blob.UploadFromStream(file.InputStream);语句导致错误。
stack trace :
堆栈跟踪 :
at Microsoft.WindowsAzure.StorageClient.Tasks.Task
1.get_Result() at Microsoft.WindowsAzure.StorageClient.Tasks.Task
1.ExecuteAndWait() at Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImpl(Func`1 impl) at Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(Stream source, BlobRequestOptions options) at Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(Stream source) at DAL.Handlers.BlobHandler.CreateAd(HttpPostedFileBase file, Advertisement model) in D:\DU Server\trunk\Du Server\DAL\Handlers\BlobHandler.cs:line 151在Microsoft.WindowsAzure.StorageClient.Tasks.Task1.get_Result()在Microsoft.WindowsAzure.StorageClient.Tasks.Task1.ExecuteAndWait()在Microsoft.WindowsAzure.StorageClient.TaskImplHelper.ExecuteImpl(Func`1 IMPL)在Microsoft.WindowsAzure.StorageClient .CloudBlob.UploadFromStream(流源,BlobRequestOptions选项)在Microsoft.WindowsAzure.StorageClient.CloudBlob.UploadFromStream(流源)在DAL.Handlers.BlobHandler.CreateAd(HttpPostedFileBase文件,广告模型)中d:\ DU服务器\树干\都Server \ DAL \ Handlers \ BlobHandler.cs:第151行
inner exception:
内在异常:
{"The remote server returned an error: (404) Not Found."}
{“远程服务器返回错误:(404)Not Found。”}
can any body help me to sort this out.
任何人都可以帮助我解决这个问题。
1 个解决方案
#1
6
Short version
简洁版本
Try the following code for BlobPropertySetting
function:
对BlobPropertySetting函数尝试以下代码:
public static CloudBlockBlob BlobPropertySetting(CloudBlobClient cloudBlobClientReferenceName, string blobContentName)
{
CloudBlockBlob blob = cloudBlobClientReferenceName.GetBlockBlobReference("upload/" + blobContentName);
return blob;
}
Now for the longer version :)
现在为更长的版本:)
The reason you're getting this error is because of the way you are constructing the CloudBlockBlob
object in BlobPropertySetting
method. When you use your code, it creates a blob object with the following URI: https://duv.blob.core.windows.net/blobContentName
. If you notice, there's no container name there. Since there's no container name, storage client library assumes that you're trying to create a blob in $root
blob container which is a special blob container. You can read more about it here: http://msdn.microsoft.com/en-us/library/windowsazure/hh488356.aspx. Since your storage account does not have this container, you get 404 - Resource Not Found
error.
您收到此错误的原因是您在BlobPropertySetting方法中构造CloudBlockBlob对象的方式。使用代码时,它会使用以下URI创建一个blob对象:https://duv.blob.core.windows.net/blobContentName。如果你注意到,那里没有容器名称。由于没有容器名称,因此存储客户端库假定您尝试在$ root blob容器中创建一个blob,这是一个特殊的blob容器。您可以在此处阅读更多相关信息:http://msdn.microsoft.com/en-us/library/windowsazure/hh488356.aspx。由于您的存储帐户没有此容器,因此您将收到404 - 未找到资源错误。
#1
6
Short version
简洁版本
Try the following code for BlobPropertySetting
function:
对BlobPropertySetting函数尝试以下代码:
public static CloudBlockBlob BlobPropertySetting(CloudBlobClient cloudBlobClientReferenceName, string blobContentName)
{
CloudBlockBlob blob = cloudBlobClientReferenceName.GetBlockBlobReference("upload/" + blobContentName);
return blob;
}
Now for the longer version :)
现在为更长的版本:)
The reason you're getting this error is because of the way you are constructing the CloudBlockBlob
object in BlobPropertySetting
method. When you use your code, it creates a blob object with the following URI: https://duv.blob.core.windows.net/blobContentName
. If you notice, there's no container name there. Since there's no container name, storage client library assumes that you're trying to create a blob in $root
blob container which is a special blob container. You can read more about it here: http://msdn.microsoft.com/en-us/library/windowsazure/hh488356.aspx. Since your storage account does not have this container, you get 404 - Resource Not Found
error.
您收到此错误的原因是您在BlobPropertySetting方法中构造CloudBlockBlob对象的方式。使用代码时,它会使用以下URI创建一个blob对象:https://duv.blob.core.windows.net/blobContentName。如果你注意到,那里没有容器名称。由于没有容器名称,因此存储客户端库假定您尝试在$ root blob容器中创建一个blob,这是一个特殊的blob容器。您可以在此处阅读更多相关信息:http://msdn.microsoft.com/en-us/library/windowsazure/hh488356.aspx。由于您的存储帐户没有此容器,因此您将收到404 - 未找到资源错误。