Looking to upload a file in my ABP-based application.
Here is how my application service is set up:
public async Task<IEnumerable<ScheduleDto>> UploadAsync(IFormFile File)
This generates a REST API endpoint like this:
https://i.sstatic.net/Q7ZON.png
Everything seems to be working fine so far.
However, the client-side proxy generated when I create it does not accept files as input. It instead creates JSON for IFormFile
:
upload = (File: IFormFile) =>
this.restService.request<any, ScheduleDto[]>({
method: 'POST',
url: `/api/app/schedule/upload`,
},
{ apiName: this.apiName });
Since this method was not really useful, I decided to use the REST service provided by the ABP framework as it handles success and failure internally. I injected the RestService
into the component:
constructor(private matchService: MatchService, private scheduleService: ScheduleService,private rest: RestService) {} //
Using that service, I made a call using the request
method and passed the file as FormData
, but nothing seemed to happen when I posted the file:
UploadSchedule(files) {
const formData = new FormData();
formData.append('file', files[0], files[0].name);
this.rest.request<FormData, ScheduleDto[]>({
method: 'POST',
url: `/api/app/schedule`,
body: formData,
});
}
I know I can upload a file using Angular's HTTP service, so it seems like there may be an issue with the way ABP generated service only supports JSON data and not FormData
.