I have an <input type='file' />
array of attachments that I post to an API, but I'm getting the files
array param empty, what am I missing? Am I declaring the correct type (IEnumerable<IFormFileCollection> files
) on the api?
The query string parameters are passing fine.
const attachments = Array.from(fileList);
const files = attachments;
const result = await apiPost(`api/attachments/addAttachments?request=${request}&&ticketId=${ticketId}`, files, {
headers: { 'Content-Type': 'multipart/form-data' },
});
And the API:
[HttpPost]
[Route("attachments")]
public async Task<string> addAttachments(string request, int ticketId, [FromBody]IEnumerable<IFormFileCollection> files)
{...}
apiPost
:
import { AdalConfig, adalFetch } from 'react-adal';
export const apiFetch: <T>(url: string, options?: object) => Promise<T> = (
url: string,
options: object,
) => adalFetch(authContext, adalConfig.endpoints.api, axios, url, options);
export const apiPost = async <T>(url: string, data: object): Promise<T> => {
const options = {
method: 'post',
data,
config: {
headers: {
'Content-Type': 'application/json',
},
},
};
return apiFetch(url, options);
};