问题
I'm trying to connect web and worker role. So i have a page where user can upload video files. Files are large so i can't use the query to send files. That's why i'm trying to upload them into the Blob Storage and then send the url by the query. But i don't know how to get this url.
Can anyone help me?
回答1:
Assuming you're uploading the blobs into blob storage using .Net storage client library by creating an instance of CloudBlockBlob
, you can get the URL of the blob by reading Uri property of the blob.
static void BlobUrl()
{
var account = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
var cloudBlobClient = account.CreateCloudBlobClient();
var container = cloudBlobClient.GetContainerReference("container-name");
var blob = container.GetBlockBlobReference("image.png");
blob.UploadFromFile("File Path ....");//Upload file....
var blobUrl = blob.Uri.AbsoluteUri;
}
View example on Pastebin
回答2:
Hey I am sorry I was not aware how I have posted the same comment once again in the answer. Please find my correct answer below with detail explanation of how this storage blob work in getting the url from blob.
// Add the connection string on the web.config file for your ease to get on multiple places if required.
<connectionStrings>
<add name="BlobStorageConnection" connectionString="DefaultEndpointsProtocol=https;AccountName=accName;AccountKey=xxxxxxxxxxxxxxxxxx YOU WILL FIND THIS in your AZURE ACCOUNT xxxxxxxxxx==;EndpointSuffix=core.windows.net"/>
This is the string which you can get from the web.config file.
string BlobConnectionString = ConfigurationManager.ConnectionStrings["BlobStorageConnection"].ConnectionString;
public string GetFileURL()
{
//This will create the storage account to get the details of account.
CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(BlobConnectionString);
//create client
CloudBlobClient cloudBlobClient = cloudStorageAccount.CreateCloudBlobClient();
//Get a container
CloudBlobContainer cloudBlobContainer = cloudBlobClient.GetContainerReference("ContainerName");
//From here we will get the URL of file available in Blob Storage.
var blob1 = cloudBlobContainer.GetBlockBlobReference(imageName);
string FileURL=blob1.Uri.AbsoluteUri;
return FileURL;
}
Like this way you can get the url of the File if you have the file (or Image) Name.
来源:https://stackoverflow.com/questions/16961933/how-to-get-blob-url-after-file-upload-in-azure