我使用ngprime fileupload
从here上传文件并将其发送到rest service
,验证swagger json
然后将文件内容保存到数据库,但在上传文件时遇到问题。angular2 primeng文件上传问题
这里是我的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>
我越来越... XMLHttpRequest cannot load http://localhost:8080/upload. Response for preflight is invalid (redirect)
错误。其实这个请求甚至不会进入我正在本地运行的休息服务......
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public ResponseEntity uploadFile(MultipartHttpServletRequest request, HttpServletResponse response, HttpServletRequest httpRequest) {
/swagger validation logic
}
我的代码中有什么问题?
基本文件上传应MultipartFile MediaType.MULTIPART_FORM_DATA_VALUE – Karthigeyan
它工作了'Angular1.4'在那里我做了同样的'http.post(URL,文件)',是无论如何上传JSON或文本文件? – user1653027