Ich versuche, ein mehrteiliges Formular mit einem binären Inneren (70 MIB) an meine API zu senden, aber ich erhalte zwei Fehlermeldungen, wenn der Upload beendet ist: < /p>
Zugriff auf xmlhttprequest unter 'https://api.contoso.com/v1/controller/upload' von Origin 'https://www.contoso.com' wurde durch CORS-Richtlinien blockiert: Nein 'Access-Control-Allow-Origin' Header ist in der angeforderten Ressource vorhanden. />
Post https://api.contoso.com/v1/controller/upload net :: err_failed 413 (Anfrage Entity zu groß) < /p>
< /blockquote>
builder.Services.Configure(options =>
{
options.Limits.MaxRequestBodySize = long.MaxValue;
options.Limits.MaxRequestBufferSize = long.MaxValue;
});
builder.Services.Configure(options =>
{
options.MultipartBodyLengthLimit = 200 * 1024 * 1024; //200 MB
});
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
//DB connection
//Blob storage connection
//Auth/JWT
//Services/DI
var app = builder.Build();
app.Logger.LogInformation("Starting...");
< /code>
In Produktion: < /p>
app.Logger.LogInformation("Production mode");
app.UseCors(policyBuilder =>
{
policyBuilder.SetIsOriginAllowed((origin) => {
app.Logger.LogInformation("Origin of call: " + origin);
return origin.Equals("https://contoso.com") || origin.Equals("https://www.contoso.com");
})
.AllowAnyHeader().AllowAnyMethod().WithExposedHeaders("App-Desktop");
});
//Allow access by the desktop app to these endpoints.
app.Use(async (context, next) =>
{
if (context.Request.Headers.ContainsKey("App-Desktop"))
{
var path = context.Request.Path.Value?.ToLower() ?? "";
app.Logger.LogInformation("Path of call from desktop app: " + path);
if (path.StartsWith("/v1/blogs"))
context.Response.Headers.Append("Access-Control-Allow-Origin", "*");
}
await next();
});
< /code>
Die betreffende Controller -Aktion: < /p>
[HttpPost("upload")]
[Consumes("multipart/form-data")]
//[RequestSizeLimit(209_715_200)] //200Mib
[DisableRequestSizeLimit]
public async Task UploadBinary(IFormFile file, [FromForm] BinaryRequest binary)
{
_logger.LogInformation("Uploading asset: " + file.FileName);
//...
}
< /code>
Überprüfen der API -Erkenntnisse auf Azure zeigt mir diese 4 Nachrichten (von oben bis unten): < /p>
Anforderung mit dem Starten von http /starten 1.1 Optionen https://api.contoso.com/v1/controller/upload - - -
Ursprung des Anruf > CORS -Richtlinienausführung erfolgreich. https://api.contoso.com/v1/controller/upload - 204 - - 2.1230ms
Die Controller -Aktion wird nie ausgeführt, also die " Das Hochladen von Asset "Die Nachricht" Meldung wird nie protokolliert. /> Was könnte der Grund dafür sein? < /p>
Das Datei -Upload schlägt fehl ⇐ C#
-
- Similar Topics
- Replies
- Views
- Last post
-
-
Das Datei -Upload schlägt mit 413 Anforderungsentität im Azure -App -Dienst fehl
by Anonymous » » in C# - 0 Replies
- 9 Views
-
Last post by Anonymous
-