用户可以在创建记录时上传图像,当您编辑该记录并尝试上传新图像时,会出现“此 blob 已存在”错误。有没有办法可以在我的应用程序中启用同名 blob 的覆盖?
这是我处理更新过程的代码。
值得注意的是,为了应用程序,我创建了图像的三个迭代,因此我包含了包含该信息的数组。
CarController.cs
private readonly int[] sizeArray = new int[] { 700, 350, 150 };
[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult Create(Car car)
{
if (ModelState.IsValid)
{
//Create the Car
_carService.InsertCar(car);
//Get the ID of the newly created car
int id = car.Id;
//Define the container name for Azure Storage
string strContainerName = "uploads";
//Blob Client
BlobServiceClient blobServiceClient = new BlobServiceClient(accessKey);
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(strContainerName);
//Iterate over the array of image sizes
foreach (var imageSize in sizeArray) …Run Code Online (Sandbox Code Playgroud) 我每天都在尝试将文件上传到 Azure 容器。
上传具有相同文件的文件时出现错误:“指定的 blob 已存在”(我想覆盖该文件)
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
conn_str = yml['AZURE_BLOB']['CONN_STR']
container_name = yml['AZURE_BLOB']['CONTAINER_NAME']
# Create the BlobServiceClient that is used to call the Blob service for the storage account
blob_service_client = BlobServiceClient.from_connection_string(conn_str=conn_str)
# Create a blob client using the local file name as the name for the blob
blob_client = blob_service_client.get_blob_client(container=container_name, blob=destination_file_name)
# Upload the created file
data = fs.open(source_path,mode='rb').read()
blob_client.upload_blob(data)
print(destination_file_name+'\t......[DONE]')
Run Code Online (Sandbox Code Playgroud)
错误信息:
azure.core.exceptions.ResourceExistsError: The specified blob already exists.
RequestId:13d062cd-801e-00a4-77c7-a81c56000000
Time:2019-12-02T04:18:06.0826908Z
ErrorCode:BlobAlreadyExists
Error:None
Run Code Online (Sandbox Code Playgroud) 我已将 Azure Function v3 项目中的所有程序集升级到版本 5.0,但我无法运行该函数。这是我函数的 csproj 文件的部分定义:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="4.0.3" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.SignalRService" Version="1.2.2" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
使用 .NET 5 实现此功能的必要解决方法是什么?谷歌没有得出任何结论。
更多信息:5.0.100 [C:\Program Files\dotnet\sdk]
这是我收到的错误消息之一:
无法加载文件或程序集“Microsoft.Extensions.Configuration.Abstractions,Version=5.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”。该系统找不到指定的文件。
如何在本地窗口中添加 azure blob 存储作为网络驱动器。有没有办法将 azure blob 安装为驱动器?
我有两个关于功能的 .net 核心应用程序的问题。我正在使用 blobtrigger。
1) 当我在本地运行我的项目时,我在命令提示符控制台上得到了这个“托管环境”,我想了解这个变量集在哪里以及如何将其更改为开发。它具有误导性,因为我只在本地开发。
[5/23/2019 7:00:20 PM] 主机启动 (773ms) [5/23/2019 7:00:20 PM] 作业主机启动 托管环境:Production 内容根路径:C:Myproject\bin\Debug\ netcoreapp2.1现在监听:http://0.0.0.0:7071
2)host.json 和 local.settings.json 有什么区别。什么时候可以使用host.json?到目前为止,我只使用了 local.settings.json,当我发布到 azure 时,我正在创建 local.settings.json 中提到的配置,但没有使用 Host.json 看起来像。host.json 文件的目的是什么。
当我想用extend生成一个新的列名,并且新的列名包含一个空格时,代码如下:
requests
| extend "users name" = ""
//other codes
Run Code Online (Sandbox Code Playgroud)
然后发生错误:无法在第 xxx 行的“=”处解析查询。所以问题是我们可以在扩展的新列名中使用空格吗?
我也试过用单引号,还是一样的错误。
我尝试在 Azure Functions 中使用依赖注入进行遥测配置。在我的函数中,当我在函数构造函数中注入 TelemetryConfiguration 时,我会解决它。我想我真的不明白我将如何在 StartUp 中使用 TelemetryConfiguration,这就是为什么我会遇到异常。我将如何添加我已经配置的 TelemetryConfiguration。
到目前为止,我在这里做了一个简单的例子。
[assembly: FunctionsStartup(typeof(StartUp))]
public class StartUp : FunctionsStartup
{
private string OmsModule { get; } = "OMS.VA";
public override void Configure(IFunctionsHostBuilder builder)
{
builder.Services.Configure<TelemetryConfiguration>(
(o) =>
{
o.InstrumentationKey = Environment.GetEnvironmentVariable("APPINSIGHTS_INSTRUMENTATIONKEY");
o.TelemetryInitializers.Add(new OperationCorrelationTelemetryInitializer());
});
}
}
public class StopPlaceUpdateTimerTrigger
{
private TelemetryClient _telemetryClient;
private string _azureWebJobsStorage;
public StopPlaceUpdateTimerTrigger(TelemetryConfiguration telemetryConfiguration)
{
_telemetryClient = new TelemetryClient(telemetryConfiguration);
}
[FunctionName("StopPlaceLoader")]
public async Task StopPlaceLoaderMain([TimerTrigger("%CRON_EXPRESSION%", RunOnStartup = true)]TimerInfo myTimerInfo, ILogger log, ExecutionContext context)
{
SetConfig(context);
var …Run Code Online (Sandbox Code Playgroud) dependency-injection azure telemetry azure-application-insights azure-functions
我正在使用应用程序见解和 nlog 配置 .net core 3 控制台应用程序
我的代码配置如下
程序.cs
.ConfigureLogging((hostingContext, logging) =>
{
logging.ClearProviders();
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
logging.AddNLog(NLog.LogManager.LoadConfiguration("nlog.config").Configuration);
})
.ConfigureServices((hostContext, services) =>
{
services.SetupConfiguration(hostContext.Configuration);
services.AddApplicationInsightsTelemetryWorkerService("--AI-Key--");
Run Code Online (Sandbox Code Playgroud)
在我的 nlog.config 中我有
<extensions>
<add assembly="NLog.Web.AspNetCore"/>
<add assembly="Microsoft.ApplicationInsights.NLogTarget" />
</extensions>
<!-- the targets to write to -->
<targets>
<target name="Console" xsi:type="Console" layout="${longdate} ${level} ${message}"/>
<target xsi:type="ApplicationInsightsTarget" name="appInsights" />
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!--All logs, including from Microsoft-->
<logger name="*" minlevel="Trace" writeTo="Console" />
<logger name="*" minlevel="Trace" writeTo="appInsights" />
</rules>
Run Code Online (Sandbox Code Playgroud)
在 …
我们已经在Azure中配置了APIM、WebApp,然后连接了AppInsights Log以获取失败时的详细信息。
我们正在 APIM 上进行负载测试。
有一次,我们开始收到 500 错误代码,这意味着应用程序级别存在问题。
当我们查看详细信息时,在某一时刻,我们得到的 http 结果代码为“故障”,并且我们在 API、服务器下没有收到任何错误。
所以我想知道“故障”是什么意思?
load-testing azure azure-api-management azure-application-insights azure-web-app-service
我想设置一个全局设置,以便null在从我的任何 HTTP 函数返回的任何响应中不返回属性。
例子:
public class User
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
[FunctionName("HttpTriggeredFunction")]
public async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Function, "get", Route = null)] HttpRequest req,
ILogger log)
{
var user = new User
{
Id = 1,
FirstName = "Chris",
LastName = null
};
return new OkObjectResult(user);
}
Run Code Online (Sandbox Code Playgroud)
返回:
{
"id": 1,
"firstName": "Chris",
"lastName": null
}
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,我不想lastName在响应中返回。
我知道您可以执行以下操作: …
azure ×9
c# ×3
.net-core ×1
asp.net-core ×1
json.net ×1
load-testing ×1
nlog ×1
python ×1
telemetry ×1