小编Rob*_*gas的帖子

如何将文件从 Angular 上传到 ASP.NET Core Web API

有人问过类似的问题,但在浏览了所有这些问题和许多关于该主题的博客文章后,我无法弄清楚这一点,所以请原谅我。

我正在创建一个简单的博客(出于这个问题的目的)两部分,Angular 8 中的前端 SPA 和 ASP.NET Core 3 中的后端 API。在我前端的一部分中,我试图上传用作新创建博客的图像的图像。当我尝试上传图像时,后端生成的 IFormFile 总是以null. 以下是代码,非常感谢任何帮助!

新博客.component.html:

<form [formGroup]="newBlogForm" (ngSubmit)="onSubmit(newBlogForm.value)">

    <div>
        <label for="Name">
            Blog Name
        </label>
        <input type="text" formControlName="Name">
    </div>

    <div>
        <label for="TileImage">
            Tile Image
        </label>
        <input type="file" formControlName="TileImage">
    </div>

    <button type="submit">Create Blog</button>

</form>
Run Code Online (Sandbox Code Playgroud)

新博客.component.ts:

import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, FormControl } from '@angular/forms';
import { BlogService } from '../blog-services/blog.service';

@Component({
  selector: 'app-new-blog',
  templateUrl: './new-blog.component.html',
  styleUrls: ['./new-blog.component.css']
})
export class NewBlogComponent implements OnInit { …
Run Code Online (Sandbox Code Playgroud)

c# typescript asp.net-core angular angular8

12
推荐指数
1
解决办法
1万
查看次数

为什么Spark中repartition比partitionBy更快?

我正在尝试将 Spark 用于一个非常简单的用例:给定大量文件(90k),其中包含数百万台设备的设备时间序列数据,将给定设备的所有时间序列读取分组到一组文件中(分割)。现在让\xe2\x80\x99s 假设我们的目标是 100 个分区,并且给定设备数据显示在同一个输出文件(只是同一个分区)中并不重要。

\n

考虑到这个问题,我们\xe2\x80\x99想出了两种方法来做到这一点 - repartitionthenwritewritewithpartitionBy应用于Writer. 其中任何一个的代码都非常简单:

\n

repartition(添加哈希列是为了确保与partitionBy下面的代码的比较是一对一的):

\n
\ndf = spark.read.format("xml") \\\n  .options(rowTag="DeviceData") \\\n  .load(file_path, schema=meter_data) \\\n  .withColumn("partition", hash(col("_DeviceName")).cast("Long") % num_partitions) \\\n  .repartition("partition") \\\n  .write.format("json") \\\n  .option("codec", "org.apache.hadoop.io.compress.GzipCodec") \\\n  .mode("overwrite") \\\n  .save(output_path)\n\n
Run Code Online (Sandbox Code Playgroud)\n

partitionBy:

\n
\ndf = spark.read.format("xml") \\\n  .options(rowTag="DeviceData") \\\n  .load(file_path, schema=meter_data) \\\n  .withColumn("partition", hash(col("_DeviceName")).cast("Long") % num_partitions) \\\n  .write.format("json") \\\n  .partitionBy(\xe2\x80\x9cpartition\xe2\x80\x9d) \\\n  .option("codec", "org.apache.hadoop.io.compress.GzipCodec") \\\n  .mode("overwrite") \\\n  .save(output_path)\n\n
Run Code Online (Sandbox Code Playgroud)\n

在我们的测试中, …

apache-spark apache-spark-sql pyspark apache-spark-xml

9
推荐指数
2
解决办法
7104
查看次数

何时应使用 IHostApplicationLifetime.OnStarted 事件与 IHostedService.StartAsync?

我一直在研究 .NET 通用主机用于托管控制台应用程序的用途。与 ASP.NET Web 应用程序相比,这似乎是 .NET 的推荐模式,允许轻松使用 DI、日志记录、配置等,同时保持一致的 API。当我遇到这个例子时,我开始有点理解了来说明 IHostApplicationLifetime 事件的使用

\n
using Microsoft.Extensions.Hosting;\nusing Microsoft.Extensions.Logging;\n\nnamespace AppLifetime.Example;\n\npublic class ExampleHostedService : IHostedService\n{\n    private readonly ILogger _logger;\n\n    public ExampleHostedService(\n        ILogger<ExampleHostedService> logger,\n        IHostApplicationLifetime appLifetime)\n    {\n        _logger = logger;\n\n        appLifetime.ApplicationStarted.Register(OnStarted);\n        appLifetime.ApplicationStopping.Register(OnStopping);\n        appLifetime.ApplicationStopped.Register(OnStopped);\n    }\n\n    public Task StartAsync(CancellationToken cancellationToken)\n    {\n        _logger.LogInformation("1. StartAsync has been called.");\n\n        return Task.CompletedTask;\n    }\n\n    public Task StopAsync(CancellationToken cancellationToken)\n    {\n        _logger.LogInformation("4. StopAsync has been called.");\n\n        return Task.CompletedTask;\n    }\n\n    private void OnStarted()\n    {\n        _logger.LogInformation("2. OnStarted has been called.");\n    }\n\n    private void …
Run Code Online (Sandbox Code Playgroud)

.net c# ihostedservice

7
推荐指数
0
解决办法
1248
查看次数