I am using ngprime fileupload
from here to upload file and send it to a rest service
which validates swagger json
and then save file content to db but facing issues while uploading file.
here is my fileupload.html
<div class="ui-g">
<p-growl [value]="msgs"></p-growl>
<form [formGroup]="uploadForm" novalidate>
<div class="ui-g-12">
<div class="ui-grid-row">
<div class="ui-grid-col-12" [ngClass]="{'has-error':!uploadForm.controls['activity'].valid && uploadForm.controls['activity'].touched}">
<div class="ui-grid-col-2"><label>Product Name </label></div>
<div class="ui-grid-col-8">
<input class="inputtext" type="text" formControlName="activity" placeholder="Product Activity"/>
<div *ngIf="uploadForm.controls['activity'].hasError('required') && uploadForm.controls['activity'].touched" class="alert alert-danger">You must enter Product Name.</div>
</div>
</div>
</div>
</div>
<div class="ui-g-12" >
<p-fileUpload name="demo[]" url="{{uploadUrl}}" (onUpload)="onUpload($event)" accept=".json,.text,.yml" maxFileSize="1000000" [disabled]="!uploadForm.valid">
<template pTemplate="content">
<ul *ngIf="uploadedFiles.length">
<li *ngFor="let file of uploadedFiles">{{file.name}} - {{file.size}} bytes</li>
</ul>
</template>
</p-fileUpload>
</div>
I am getting ...
XMLHttpRequest cannot load http://localhost:8080/upload. Response for preflight is invalid (redirect)
error. Actually the request not even going to my rest serevice which I am running locally ...
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public ResponseEntity uploadFile(MultipartHttpServletRequest request, HttpServletResponse response, HttpServletRequest httpRequest) {
/swagger validation logic
}
what's the issue in my code?
Angular1.4
where I did samehttp.post(url, file)
, is there anyway to upload json or text files? - user1653027