コード例 #1
0
        public IHttpActionResult Blob(string path, string accountName)
        {
            if (String.IsNullOrEmpty(path) ||
                String.IsNullOrEmpty(accountName))
            {
                return(Unauthorized());
            }

            // When linking to a blob, we must resolve the account name to handle cases
            // where multiple storage accounts are being used.
            CloudStorageAccount account = AccountProvider.GetAccountByName(accountName);

            if (account == null)
            {
                return(Unauthorized());
            }

            BlobPath            parsed     = BlobPath.Parse(path);
            LocalBlobDescriptor descriptor = new LocalBlobDescriptor
            {
                ContainerName = parsed.ContainerName,
                BlobName      = parsed.BlobName
            };
            var blob = descriptor.GetBlockBlob(account);

            // Get a SAS for the next 10 mins
            string sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy
            {
                Permissions            = SharedAccessBlobPermissions.Read,
                SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(10)
            });

            // Redirect to it
            return(Redirect(blob.Uri.AbsoluteUri + sas));
        }