AngularJS -API -Postdatei in den Parameter der .NET -App -App -Endpunkt -Datei ist nullC#

Ein Treffpunkt für C#-Programmierer
Anonymous
 AngularJS -API -Postdatei in den Parameter der .NET -App -App -Endpunkt -Datei ist null

Post by Anonymous »

Ich verwende ALD AngularJS und versuche die Datei hochladen und api -Aufruf durchführen. API ist eine .NET -Core -App. Ich kann die Anforderung mit dem Breakpoint in der API sehen, aber der Parameter ist immer null. < /p>
Hier ist der AngularJS -Code < /p>
vm.uploadMotorFactor = function () {
let uploadUrl = `/api/Membership/UploadMotorFactor`;

let fileInput = document.getElementById('motorFactorFile');
let file = fileInput.files[0];

if (!file) {
alert("Please select a CSV file to upload.");
return;
}

let formData = new FormData();
formData.append('file', file); // Matches the property name in ImportFileDataRequest

$http.post(uploadUrl, formData, {
headers: { 'Content-Type': undefined }, // Let the browser set the correct multipart boundary
transformRequest: angular.identity
}).then(response => {
alert('File uploaded successfully!');
fileInput.value = ''; // Clear the file input after successful upload
}).catch(error => {
console.error('Error uploading file:', error);
alert('File upload failed.');
});
};
< /code>
Dies ist mein API -Endpunkt < /p>

Code: Select all

 [HttpPost]
public async Task UploadMotorFactor([FromForm] IFormFile file)
{
try
{
return file != null ? Ok() : StatusCode(StatusCodes.Status500InternalServerError);

}
catch (Exception e)
{
_logger.LogError(e, "Failed to download Motor factor");
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
Ich habe 'Inhaltstyp', 'Multipart/Form-Data' auch verwendet, aber das Ergebnis ist das gleiche, was ich hier fehlt? /> Es ist ein altes AngularJS und sieht so aus: < /p>

Code: Select all


Upload

this is the js file:

const mycommadashboard = angular.module("umbraco");

mycommadashboard.controller("MyDashboardController",
function ($scope, $http, $timeout, Upload) {
let vm = this;
vm.uploadMotorFactor = function () {

};

});

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post