from azure.storage.blob import BlobServiceClient
# get your connection_string - look at docs
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
container_client = blob_service_client.get_container_client(storage_container_name)
You can call blob_client.url
blob_client = container_client.get_blob_client("myblockblob")
with open("pleasedelete.txt", "rb") as data:
blob_client.upload_blob(data, blob_type="BlockBlob")
print(blob_client.url)
const { BlobServiceClient } = require('@azure/storage-blob')
const AZURE_STORAGE_CONNECTION_STRING = '<connection string>'
async function main() {
// Create the BlobServiceClient object which will be used to create a container client
const blobServiceClient = BlobServiceClient.fromConnectionString(AZURE_STORAGE_CONNECTION_STRING);
// Make sure your container was created
const containerName = 'my-container'
// Get a reference to the container
const containerClient = blobServiceClient.getContainerClient(containerName);
// Create a unique name for the blob
const blobName = 'quickstart.txt';
// Get a block blob client
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
console.log('\nUploading to Azure storage as blob:\n\t', blobName);
// Upload data to the blob
const data = 'Hello, World!';
await blockBlobClient.upload(data, data.length);
console.log("Blob was uploaded successfully. requestId: ");
console.log("Blob URL: ", blockBlobClient.url)
}
main().then(() => console.log('Done')).catch((ex) => console.log(ex.message));
<connectionStrings>
<add name="BlobStorageConnection" connectionString="DefaultEndpointsProtocol=https;AccountName=accName;AccountKey=xxxxxxxxxxxxxxxxxx YOU WILL FIND THIS in your AZURE ACCOUNT xxxxxxxxxx==;EndpointSuffix=core.windows.net"/>
这是您可以从web.config文件中获取的字符串。
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;
}
6条答案
按热度按时间nzkunb0c1#
假设您通过创建
CloudBlockBlob
的示例,使用.Net存储客户端库将blob上载到blob存储中,则可以通过阅读blob的Uri
属性来获取blob的URL。View example on Pastebin
swvgeqrz2#
对于python用户,可以使用
blob_client.url
遗憾的是,https://learn.microsoft.com中未记录此操作
将返回
https://pleasedeleteblob.blob.core.windows.net/pleasedelete-blobcontainer/myblockblob
w6mmgewl3#
当你使用更新的 “Azure存储Blob” 包时,请使用以下代码。
62lalag44#
截至2020年的完整工作Javascript解决方案:
zu0ti5jz5#
这是V12的方法。我不能保证我的变量名是准确的,但是代码可以工作。
9bfwbjaz6#
嘿,我很抱歉,我不知道我是如何张贴同样的评论再次在答案。请找到我的正确答案下面详细解释如何从blob存储blob工作的网址。
//在web.config文件中添加连接字符串,以便在需要时轻松地在多个位置获取。
这是您可以从web.config文件中获取的字符串。
像这样,如果你有文件(或图像)名称,你可以得到文件的URL。