我有一个 Azure 存储帐户,并且启用了 Blob 服务上的静态网站。我还为我的 blob 服务配置了自定义域。为了能够在自定义域上通过 HTTPS 为我的网站提供服务,我需要以某种方式应用我的证书。我该怎么做?
ps 我不想没有 CDN
我有一个 Azure 帐户,采用即用即付订阅方式。我创建了存储帐户,如以下链接中所述
https://learn.microsoft.com/en-us/azure/active-directory-b2c/tutorial-customize-ui
但我无法更改容器的公共访问级别。它始终作为附加图像被禁用。
任何人都可以帮助我启用此功能。我花了很多时间阅读文档。但找不到任何。
与此相关的文档似乎非常混乱。看来使用现在已弃用的Microsoft.Azure.Storage.Blobnuget 包使用该CloudBlobContainer.AcquireLease方法是可能的。
更新后的BlobLeaseClient方法Acquire()指出:
Acquire(TimeSpan, RequestConditions, CancellationToken) 操作获取blob或容器的租约。
但尚不清楚如何使用它。尽管我找到了已弃用的软件包的示例,但我找不到任何这样的示例。
目前我有这个:
//injected using AddBlobServiceClient, etc. Uses DefaultAzureCredential
private BlobContainerClient blobContainerClient;
blobContainerClient = blobServiceClient.GetBlobContainerClient("containerName");
BlobLeaseClient blc = blobContainerClient.GetBlobLeaseClient();
//throws exception here
BlobLease bl = await blc.AcquireAsync(new TimeSpan(0, 0, 30));
Run Code Online (Sandbox Code Playgroud)
但当我运行这个时,我只是得到:
The value for one of the HTTP headers is not in the correct format.
RequestId:<guid>
Time:2020-09-30T10:28:47.8781946Z
Status: 400 (The value for one of the HTTP headers is not in the correct format.)
ErrorCode: InvalidHeaderValue …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 Python 中的 Azure 存储 Blob 读取机器学习模型的权重。这应该在 Azure Functions 中运行,所以我不相信我能够使用将 blob 保存到磁盘的方法。
我使用的是 azure-storage-blob 12.5.0,而不是旧版本。
我尝试使用Dill.loads加载 .pkl 文件,如下所示:
connection_string = 'my_connection_string'
blob_client = BlobClient.from_connection_string(connection_string, container_name, blob_name)
downloader = blob_client.download_blob(0)
with BytesIO() as f:
downloader.readinto(f)
weights = dill.loads(f)
Run Code Online (Sandbox Code Playgroud)
返回:
>>> TypeError: a bytes-like object is required, not '_io.BytesIO'
Run Code Online (Sandbox Code Playgroud)
我不确定使用 Pickle 的方法会如何。怎么解决这个问题呢?
在 Microsoft.Azure.Storage.Blob 库中,您可以使用 SAS URI 创建 Blob 上传客户端。
var cloudBlockBlob = new CloudBlockBlob(blobSasUri);
Run Code Online (Sandbox Code Playgroud)
但是,该库已被弃用,取而代之的是 Azure.Storage.Blobs。我不确定如何使用 SAS URI 创建 BlobContainerClient 实例,因为该类的构造函数都不允许使用 URI 参数。这可能吗?或者我是否只需要使用 HttpClient 来调用 Blob 服务?
.txt我正在尝试读取我所拥有的文件的值azure blob storage。
到目前为止我的代码:
BlobServiceClient BlobServiceClient = new BlobServiceClient("connectionstring");
var containerClient = BlobServiceClient.GetBlobContainerClient("staging");
var blobClient2 = containerClient.GetBlockBlobClient($"myfile.txt");
var date = blobClient2.DownloadAsync().Result;
Run Code Online (Sandbox Code Playgroud)
但这会返回元数据,如何获取.txt文件中的实际文本?
我一直在尝试开发 Blazor WebAssembly 应用程序(我正在尝试使用 .NET Standard 2.1 和 .NET 5.0),我的目标是允许用户使用选择文件InputFile并将该文件上传到 Azure Blob 存储容器。我四处寻找并遵循不同的指南,但没有成功。我遇到的问题通常与安全相关,例如 CORS(尽管已完全设置)、授权失败以及 System.PlatformNotSupportedException:此平台不支持 System.Security.Cryptography.Algorithms。
不管这是否是好的做法;是否可以直接从 blazor 应用程序上传到 blob 存储?我尝试过的一种方法是通过SAS令牌。它通过控制台应用程序运行,但不能通过 BLAZOR 应用程序运行。
<label for="browseData"><b>Browse File</b></label>
<p><InputFile id="browseData" OnChange="@OnInputFileChange" /></p>
private async Task OnInputFileChange(InputFileChangeEventArgs e)
{
var maxAllowedFiles = 1;
var inputFile = e.GetMultipleFiles(maxAllowedFiles).First();
var stream = inputFile.OpenReadStream();
await StorageService.UploadFileToStorage(stream, "sftp-server", inputFile.Name);
}
Run Code Online (Sandbox Code Playgroud)
仓储服务
public class AzureStorageService
{
private readonly IAzureStorageKeyService _azureStorageKeyService;
public AzureStorageService(IAzureStorageKeyService azureStorageKeyService)
{
_azureStorageKeyService = azureStorageKeyService;
}
public async Task<Uri> UploadFileToStorage(Stream stream, string …Run Code Online (Sandbox Code Playgroud) file-upload azure-blob-storage blazor shared-access-signatures
我正在寻找更新/覆盖一个简单的天蓝色 blob 的内容,该 blob 包含一个 txt 文件,其中包含简单的日期字符串。我用它来存储某个进程的最后运行时间。
我尝试了几种方法,但没能找到任何对我的事业有帮助的文档。任何帮助或建议表示赞赏。
import datetime
from azure.storage.blob import BlobServiceClient, BlobClient
maxdate = datetime.datetime.now()
now = maxdate.strftime("%m-%d-%YT%H:%M:%S")
def upload_to_blob(data):
conn_str = "<conn_str>"
blob_service_client = BlobServiceClient.from_connection_string(conn_str)
blob_client = blob_service_client.get_blob_client(container="vstscontainerreleases", blob="last_run.txt")
blob_client.upload_blob(data)
upload_to_blob(now)
Run Code Online (Sandbox Code Playgroud)
我已经尝试了上述简单的重新上传相同的 blob,但收到一条错误消息,指出 blob 已存在。
Time:2021-08-18T11:53:00.0692411Z
ErrorCode:BlobAlreadyExists
Error:None
Run Code Online (Sandbox Code Playgroud) 我有一个SAS 令牌,格式如下:
https://name.blob.core.windows.net/container?sv=2015-04-05&sr=b&sig=abc123&se=2017-03-07T12%3A58%3A52Z&sp=rw
我正在尝试使用AzPowershell 中提供的 Cmdlet 将内容上传到此 blob。我无法找到仅需要上述 SAS 令牌和要上传的文件的 API。
读了这篇reddit 帖子,我的选择似乎是:
StorageAccountName(在示例中name)、Container(在示例中container) 和SASToken(在上例中sv=2015-04-05&sr=b&sig=abc123&se=2017-03-07T12%3A58%3A52Z&sp=rw),然后使用New-AzStorageContext/ Set-AzStorageBlobContent。这或多或少是此 StackOverflow 帖子中的答案(仅使用 SAS 令牌连接到 Azure 存储帐户?)Invoke-WebRequest或其同类基本上自己执行 REST 调用。我想使用Az尽可能多的提供的 cmdlet,因此从选项 1 开始,似乎没有 API 可以解析它,我能找到的最接近的是这个 StackOverflow 帖子(使用 SAS 令牌上传 Blob 内容)谈论使用CloudBlockBlob,但是尚不清楚该类是否可以在 PowerShell 中使用。
为此,我创建了一个似乎有效的正则表达式,但很可能很脆弱,有更好的方法吗?
$SASUri = https://name.blob.core.windows.net/container?sv=2015-04-05&sr=b&sig=abc123&se=2017-03-07T12%3A58%3A52Z&sp=rw
$fileToUpload = 'Test.json'
$regex = [System.Text.RegularExpressions.Regex]::Match($SASUri, …Run Code Online (Sandbox Code Playgroud) azure ×7
c# ×4
asp.net-mvc ×1
azure-sas ×1
blazor ×1
certificate ×1
dill ×1
file-upload ×1
pickle ×1
powershell ×1
python ×1
web ×1