Reputation: 533
I'm working out of my local VS (2013 for one project, 2015 for the other.) I'm new to blobs and security, I had to pick up someone else's project which had slow upload speeds because they were uploading from the client browser to blob storage, and then taking the blob, creating a media asset and encoding the asset as mp4. Well I'm trying to put the encoding and creation of the media asset into a background process.
When I run localhost, I can upload and save to blob storage without a problem. I can see the blob in the Azure Portal, and have even set the access type on the blob to container. But when I try to retrieve the blob from background storage, it looks like I am getting a handle to the blob, but when I try to make a call to blob.FetchAttributes() I get a 404. I am using the correct storage connection string. There is a SAS token added to the URL (good for 1 year) and I have tried with and without the token.
I wrote this quick console app shown below, and when the blobs in the container are enumerated I see the blob that I uploaded, and that it has the correct size. Yet the call to blob.Exists() fails everytime. The redacted URL I am using for the fileName var to get the blob reference is being copied directly from the Azure portal. I have the correct credentials in my connection string, so I am not sure what is going on here. Any explanation would be greatly appreciated.
private static void ListBlobs()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse( CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
var container= blobClient.GetContainerReference("streamingfiles");
// Loop over items within the container and output the length and URI.
foreach (IListBlobItem item in container.ListBlobs(null, false))
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
Console.WriteLine("Block blob of length {0}: {1}", blob.Properties.Length, blob.Uri);
}
}
var fileName = "https://redacted.blob.core.windows.net/streamingfiles/47a49fb7-6f44-4f56-9695-37a4ddcd0f4a_56.mp4";//tried also with sas token
var sourceCloudBlob = container.GetBlockBlobReference(fileName);
if (sourceCloudBlob.Exists())
Console.WriteLine("Exists");
else
Console.WriteLine("Does Not Exist"); //alwayd doesn't exist
}
Upvotes: 0
Views: 565
Reputation: 533
I'm an idiot. What's the point of passing the full path to the file when I already am in the container: var fileName = "47a49fb7-6f44-4f56-9695-37a4ddcd0f4a_56.mp4";
Dev-One made me stop and think about it, but I can't mark that as correct.
Upvotes: 0
Reputation: 4401
An alternative to container.GetBlockBlobReference(fileName).Exists();
Set the flatBlobListing
flag to true
, since the blob structure are of flat hierarchy.
// Loop over items within the container and output the length and URI.
foreach (IListBlobItem item in container.ListBlobs(null, true))
{
if (item.GetType() == typeof(CloudBlockBlob))
{
CloudBlockBlob blob = (CloudBlockBlob)item;
if (blob != null)
{
blob.FetchAttributes();
Console.WriteLine("Fetching Attributes");
string blobFilePath = blob.Uri.AbsolutePath.ToString();
if(String.compare(blobFilePath, filename, true) == 0)
{
Console.WriteLine("Exists");
}
else
{
Console.WriteLine("Does Not Exist")
}
Console.WriteLine("Block blob of length {0}: {1}", blob.Properties.Length, blob.Uri);
}
}
}
Upvotes: 0