大家好,我在Angular 4.3 + Spring Boot Rest应用程序上发布多部分表单数据时遇到问题。无论我在Java方法中作为参数放置什么,我都会收到消息“必需请求部分'arquivo'不存在”或“必需请求参数'arquivo'不存在”。
以下是表单代码的一部分:
> t1
n_1 n_2 n_3
1 3 4 3
2 5 7 5
3 2 3 2
发布方法:
<form (ngSubmit)="onFormSubmit()" [formGroup]="formulario" enctype="multipart/form-data">
<div formGroupName="sumarizacao">
<div class="row">
<!-- Nome da sumarização -->
<div class="form-group col-sm-3">
<label for="summarizationName">*Nome da Sumarização</label>
<input type="text" class="form-control" id="summarizationName" formControlName="nome" placeholder="Nome">
<div *ngIf="formulario.controls['sumarizacao'].controls['nome'].errors && formulario.controls['sumarizacao'].controls['nome'].dirty"><small> Campo obrigatório</small></div>
</div>
<!-- control file upload -->
<div class="form-group col-sm-9">
<label class="form-control-label custom-submit" id="controlFileLabel" for="envio-arquivo-ctl">Arquivo de controle</label>
<i class="fa fa-check-circle" aria-hidden="true" *ngIf="file != null"></i>
<div>
<input type="file" id="envio-arquivo-ctl" (change)="fileEvent($event)" accept=".ctl">
<div *ngIf="file != null"><p>{{file.name}}</p></div>
<div *ngIf="formulario.controls['arquivo'].name != '' && formulario.controls['arquivo'].dirty"><small> Campo obrigatório</small></div>
</div>
</div>
</div>
<button type="submit" class="btn btn-sm btn-primary" [disabled]="formulario.invalid"><i class="fa fa-check" aria-hidden="true"></i> Gravar</button>
<button type="reset" class="btn btn-sm btn-danger"><i class="fa fa-ban"></i> Resetar</button>
</form>
当我打印formData或formGroup时,它看起来很好,所有数据都在那里,但看起来当它到达后端时它会崩溃。
salvarSumarizacao(formGroup: FormGroup): Observable<Sumarizacao> {
let formData = new FormData();
let header = new HttpHeaders().set('enctype', 'multipart/form-data').set('Accept', 'application/json');
formData.append('sumarizacao', JSON.stringify(formGroup.value.sumarizacao));
if (formGroup.value.arquivo !== '') {
formData.append('arquivo', formGroup.value.arquivo, formGroup.value.arquivo.name);
}
return this.http.post(URIConstantes.SUMARIZACAO, formData, { headers: header })
.map(resp => resp as Sumarizacao)
.catch(this.handleErrorObservable)
}
当我把HttpServletRequest作为参数时,它给了我null multiPartfiles和MultipartParametersName
当我输入参数(@RequestBody String test)时,'test'字符串给我整个请求体(所有表单数据和文件数据为字符串,包括边界)
当我发布到http://httpbin.org/post时,它有效,我得到的回复是: enter image description here
我已经尝试过使用@RequestPart,@ RequestParam和两者,它向我显示“必需的参数/部分不存在”。我也试过@FormDataParam,对象来了null。 :(
答案 0 :(得分:0)
我使用了MultipartHttpServletRequest参数和CommonMultipartResolver bean。
Mixin "useKeyframes" does not accept a content block.
我使用Spring Boot 1.5.3,Spring Security 3.2.10和Spring Core 4.3.8