Загрузка файлов как часть отправки более крупной формы в одном запросе (минимальные API)C#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 Загрузка файлов как часть отправки более крупной формы в одном запросе (минимальные API)

Сообщение Anonymous »

Я пытаюсь загрузить документы через IFormFileCollection как часть отправки более крупной формы (в одном запросе). Каждый документ имеет дополнительные метаданные, такие как тип документа, имя документа и описание документа.
[img]https://i.sstatic. net/rBSBsMkZ.png[/img]

Получаю сообщение об ошибке:

Произошло необработанное исключение при выполнении запроса.
Microsoft.AspNetCore.Http.BadHttpRequestException: отсутствует необходимое значение для свойства LegalEntity.

Это моя полезная нагрузка:
{
"legalEntity": {
"name": "Acme Corporation",
"shortName": "Acme Corp",
"type": "Organization",
"registrationNumber": "REG123456",
"dateOfIncorporation": "2000-01-01T00:00:00",
"taxIdentificationNumber": "TAX987654",
"country": "United States",
"industryType": "Technology",
"creditLimit": 1000000.00,
"contactInformation": {
"primaryContactName": "John Doe",
"primaryContactPhoneNumber": "+1 (555) 123-4567",
"primaryContactEmail": "john.doe@acmecorp.com",
"secondaryContactName": "Jane Smith",
"secondaryContactPhoneNumber": "+1 (555) 987-6543",
"secondaryContactEmail": "jane.smith@acmecorp.com",
"website": "https://www.acmecorp.com"
},
"addressInformation": {
"street": "123 Tech Street",
"city": "Silicon Valley",
"state": "CA",
"postalCode": "94000"
},
"bankInformation": {
"accountName": "Acme Corporation Operating Account",
"accountNumber": "1234567890",
"swiftCode": "TECHUS123",
"iban": "DE89370400440532013000",
"bankAddress": "456 Bank Street, Silicon Valley, CA 94000, USA"
},
"kycInformation": {
"status": "Pending",
"riskRating": "Low",
"amlStatus": "Compliant",
"sanctionsCheckStatus": "Passed",
"complianceNotes": "Initial compliance review completed",
"parentCompany": null,
"documents": [
{
"documentType": "Certificate of Incorporation",
"documentName": "acme_incorporation.pdf",
"documentDescription": "Certificate of Incorporation for Acme Corp"
}
]
},
"uboInformation": {
"name": "John Doe",
"ownershipPercentage": 100.00,
"nationality": "United States",
"identificationNumber": "123-45-6789"
}
}
}

Это конечная точка:
public class CreateLegalEntityEndpoint : IEndpoint
{
public static void MapEndpoint(IEndpointRouteBuilder endpoints)
{
ArgumentNullException.ThrowIfNull(endpoints);

endpoints.MapPost("/legalentities",
async ([FromForm] CreateLegalEntityCommand command, ISender sender, CancellationToken cancellationToken) =>
{
var result = await sender.Send(command, cancellationToken);
return result.Match(id => Results.Created($"/legalentities/{id}", id), CustomResults.Problem);
})
.Produces(StatusCodes.Status201Created)
.ProducesValidationProblem()
.ProducesProblem(StatusCodes.Status500InternalServerError)
.DisableAntiforgery() // See: https://learn.microsoft.com/en-us/dotne ... ery-checks
.WithTags(nameof(LegalEntity))
.WithOpenApi(operation => new OpenApiOperation(operation)
{
Summary = "Create a new legal entity",
Description = "Creates a new legal entity with all its related information"
});
}
}

public sealed record CreateLegalEntityCommand : IRequest
{
public required LegalEntityDto LegalEntity { get; init; }
public required IFormFileCollection Documents { get; init; }
}


Подробнее здесь: https://stackoverflow.com/questions/791 ... st-minimal
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»