I need to parse a JSON file into an object before sending it for validation in an API call. The current code is not working and the API requires an object.
<label class="form-label required" for="file">File</label>
<label
class="button secondary wide required"
for="file"
(click)="inputFileTarget.click()"
>
Select JSON file
</label>
<input
id="inputFileTarget"
#inputFileTarget
type="file"
class="hidden"
accept=".json"
formControlName="fileInput"
(change)="onFileChange($event)"
/>
component:
const formData = new FormData();
formData.append('file', this.importForm.get('fileSource').value);
this.wizard.next();
this.validateUploadedTemplate(formData);
private validateUploadedTemplate(formData: any): void {
this.templateUploadService.validate(formData)
.subscribe(result => {
console.log('result', result);
})
}
[HttpPost]
[ResponseType(typeof(Boolean))]
[Route("validate-definition", Name = "ValidateAuditTemplate")]
[RequiredActivity(RadarModuleKeys.EnhancedAudits, EnhancedAuditActivities.ManageEnhancedAudits)]
public async Task<IHttpActionResult> ValidateAuditTemplate(TemplateDefinition template)
{
return Ok(await Task.FromResult(true));
}