how to get blob-URL after file upload in azure

前端 未结 2 883
野性不改
野性不改 2021-02-11 13:00

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

相关标签:
2条回答
  • 2021-02-11 13:56

    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

    0 讨论(0)
  • 2021-02-11 14:03

    full working Javascript solution as of 2020:

    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 = 'speechlab'
    
      // 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));
    
    0 讨论(0)
提交回复
热议问题