我一直在尝试开发 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
我已经尝试了 Stackoverflow 上的几篇文章和线程,但似乎没有任何进展。我试图从 YAML 步骤中调用的 .py 文件中获取一个变量,并将该变量设置为全局使用。
在我的 。我有py 文件
print(f'##vso[task.setvariable variable=AMLPipelineId;isOutput=true]{pipelineId}')
Run Code Online (Sandbox Code Playgroud)
然后在我的 YAML 管道步骤中我有
- task: AzurePowerShell@5
displayName: 'Run AML Pipeline'
inputs:
azureSubscription: '$(azureSubscription)'
ScriptType: 'InlineScript'
name: AmlPipeline
azurePowerShellVersion: 'LatestVersion'
pwsh: true
Inline: |
$username = "$(ARM_CLIENT_ID)"
$password = "$(ARM_CLIENT_SECRET)"
$tenantId = "$(ARM_TENANT_ID)"
python $(Pipeline.Workspace)/AML_Pipeline/build_aml_pipeline.py --wsName $(wsName) --resourceGroup $(ResourceGroupName) --subscriptionId $(subId)
$MLPipelineId = $AmlPipeline.AMLPipelineId
Run Code Online (Sandbox Code Playgroud)
但这个变量似乎是空的。我知道还有其他方法可以使用“设置变量”,但这是我最新的尝试,例如print('##vso[task.setvariable variable=version;]%s' % (version))
所以我有一个由 N 个字母“a”或“b”组成的字符串 S。如果 A 的所有出现都在 b 的所有出现之前,则应返回 1,否则返回 0。
B 不需要出现在 S 中,A 不需要出现在 S 中
例如
S='aabbb' returns 1
S = 'ba' returns 0
S = 'aaa' returns 1
S= 'b' returns 1
Run Code Online (Sandbox Code Playgroud)
所以我的方法是在字符串上使用 for 循环并检查 b 是否出现在 a 之前,如下所示:
char newstr[10] = "aabbba"; //should return 0
int len = strlen(newstr);
for (int i = 0; i < len+1; i++) {
printf("%c", newstr[i]);
if (newstr[i] < 'b') {
printf("1");
}
else {
printf("0");
}
}
Run Code Online (Sandbox Code Playgroud)
输出是a1a1b0b0b0a1 1 …