Я использую ALD AngularJs и пробую файл загрузки и DO API -вызов, API - это приложение .NET Core, я могу видеть запрос, используя точку останова в API, но параметр всегда приходит NULL. 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>
Это моя конечная точка API < /p>
[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);
}
}
Я использовал 'контент-тип', 'Multipart/form-data' , но результат одинаково, то, что мне здесь не хватает? это старый AngularJs и выглядит так: < /p>
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 () {
};
});
Подробнее здесь: https://stackoverflow.com/questions/794 ... er-is-null
AngularJS API -файл Post File к параметру конечной точки приложения .NET Core App Appaint Null ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
AngularJS API -файл Post File к параметру конечной точки приложения .NET Core App Appaint Null
Anonymous » » в форуме C# - 0 Ответы
- 5 Просмотры
-
Последнее сообщение Anonymous
-
-
-
AngularJS API -файл Post File к параметру конечной точки приложения .NET Core App Appaint Null
Anonymous » » в форуме C# - 0 Ответы
- 8 Просмотры
-
Последнее сообщение Anonymous
-