我正试图使用重新安装库,使用以下说明将文件发布到我的后端
但我没能做到这一点。我发现这个问题似乎表明我正在做同样的事情,但它没有帮助:https://github.com/reactiveui/refit/issues/991
//refit api
[Multipart]
[Post("/api/cluster/deploy")]
Task PostDeployAsync([AliasAs("file")] StreamPart stream);
//my backend controller
[HttpPost("deploy"), DisableRequestSizeLimit]
public async Task PostDeployAsync(IFormFile file)
{
//blazor code
<Blazorise.FileEdit Changed="@OnChanged" />
async Task OnChanged(FileChangedEventArgs e)
{
foreach (var file in e.Files)
{
var fs = file.OpenReadStream();
await _api.PostDeployAsync(new StreamPart(fs, file.Name, "application/zip", file.Name));
在我的控制器中,IFormFile file
为空。我做错了什么?
以下是我用来验证改装零件是否有问题的方法。这样,控制器上的file
就可以正确填充。
@inject HttpClient http
var fileContent =
new StreamContent(file.OpenReadStream(maxFileSize));
fileContent.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
using var content = new MultipartFormDataContent();
content.Add(
content: fileContent,
name: ""files"",
fileName: file.Name);
var response =
await http.PostAsync("api/cluster/deploy", content);
看起来问题是StreamPart
的最后一个参数。我改变了我的控制器以接受CCD_ 4;文件";作为StreamPart
:的最终参数
await _api.PostDeployAsync(new StreamPart(fs, file.Name, "application/zip", "files"));
[HttpPost("deploy"), DisableRequestSizeLimit]
public async Task PostDeployAsync(IEnumerable<IFormFile> files)