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);
}
}
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 () {
};
});