您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Spring Boot + Angular文件上传无法两次上传同一文件

Spring Boot + Angular文件上传无法两次上传同一文件

这个:

formData.append("selectFile", this.data);
@H_404_5@

对此:

formData.append("file", this.data);
@H_404_5@

原因

public ResponseEntity<String> handleFileUpload(@RequestParam("file")
@H_404_5@
   

          

解决方法

Chrome中网络下的错误

{ timeStamp: ......,status: 400
  error: 'Bad Request',message: 'Required request part 'file' is not present'
  path: 'url as hosted on Tomcat'
}

Spring Boot Controller.java文件

@PostMapping("/Post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") 
MultipartFile file){ String Message=""; try .......(and so on)}

我的角度组件

<form [formGroup]="uploadForm" (ngSubmit) = "onSubmit()">
<input type="file" id="selectFile" formControlName="file1" name="selectFile"
(change)="fileEvent($event)"/>

<input type="submit" name="Submit"/>
</form>

Component.ts文件

fileEvent(e) {
 this.data = e.target.files[0];
}
omSubmit() {
  let headers: any = new Headers();
  headers.append('Content-type','undefined');
  let formData = new FormData();
  formData.append("selectFile",this.data);
  const req5 = new HttpRequest('POST','url as hosted on TOMCAT',formData,reportProgress: true,responseType: 'text'
  });
  return this.httpClient.request(req5).subscribe(e => {(
  console.log(e);
  )}
}

我在哪里出错?

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!
formData.append("file", this.data);
@H_404_5@

原因

public ResponseEntity<String> handleFileUpload(@RequestParam("file")
@H_404_5@
  

          

解决方法

Chrome中网络下的错误

{ timeStamp: ......,status: 400
  error: 'Bad Request',message: 'Required request part 'file' is not present'
  path: 'url as hosted on Tomcat'
}

Spring Boot Controller.java文件

@PostMapping("/Post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") 
MultipartFile file){ String Message=""; try .......(and so on)}

我的角度组件

<form [formGroup]="uploadForm" (ngSubmit) = "onSubmit()">
<input type="file" id="selectFile" formControlName="file1" name="selectFile"
(change)="fileEvent($event)"/>

<input type="submit" name="Submit"/>
</form>

Component.ts文件

fileEvent(e) {
 this.data = e.target.files[0];
}
omSubmit() {
  let headers: any = new Headers();
  headers.append('Content-type','undefined');
  let formData = new FormData();
  formData.append("selectFile",this.data);
  const req5 = new HttpRequest('POST','url as hosted on TOMCAT',formData,reportProgress: true,responseType: 'text'
  });
  return this.httpClient.request(req5).subscribe(e => {(
  console.log(e);
  )}
}

我在哪里出错?

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!
public ResponseEntity<String> handleFileUpload(@RequestParam("file")
@H_404_5@
 

          

解决方法

Chrome中网络下的错误

{ timeStamp: ......,status: 400
  error: 'Bad Request',message: 'Required request part 'file' is not present'
  path: 'url as hosted on Tomcat'
}

Spring Boot Controller.java文件

@PostMapping("/Post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") 
MultipartFile file){ String Message=""; try .......(and so on)}

我的角度组件

<form [formGroup]="uploadForm" (ngSubmit) = "onSubmit()">
<input type="file" id="selectFile" formControlName="file1" name="selectFile"
(change)="fileEvent($event)"/>

<input type="submit" name="Submit"/>
</form>

Component.ts文件

fileEvent(e) {
 this.data = e.target.files[0];
}
omSubmit() {
  let headers: any = new Headers();
  headers.append('Content-type','undefined');
  let formData = new FormData();
  formData.append("selectFile",this.data);
  const req5 = new HttpRequest('POST','url as hosted on TOMCAT',formData,reportProgress: true,responseType: 'text'
  });
  return this.httpClient.request(req5).subscribe(e => {(
  console.log(e);
  )}
}

我在哪里出错?

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!
{ timeStamp: ......,status: 400
  error: 'Bad Request',message: 'Required request part 'file' is not present'
  path: 'url as hosted on Tomcat'
}
@PostMapping("/Post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") 
MultipartFile file){ String Message=""; try .......(and so on)}
<form [formGroup]="uploadForm" (ngSubmit) = "onSubmit()">
<input type="file" id="selectFile" formControlName="file1" name="selectFile"
(change)="fileEvent($event)"/>

<input type="submit" name="Submit"/>
</form>
fileEvent(e) {
 this.data = e.target.files[0];
}
omSubmit() {
  let headers: any = new Headers();
  headers.append('Content-type','undefined');
  let formData = new FormData();
  formData.append("selectFile",this.data);
  const req5 = new HttpRequest('POST','url as hosted on TOMCAT',formData,reportProgress: true,responseType: 'text'
  });
  return this.httpClient.request(req5).subscribe(e => {(
  console.log(e);
  )}
}

对此:

原因

Chrome中网络下的错误

Spring Boot Controller.java文件

我的角度组件

Component.ts文件

我在哪里出错?

对此:

formData.append("file", this.data);
@H_404_5@

原因

public ResponseEntity<String> handleFileUpload(@RequestParam("file")
@H_404_5@
  

          

解决方法

Chrome中网络下的错误

{ timeStamp: ......,status: 400
  error: 'Bad Request',message: 'Required request part 'file' is not present'
  path: 'url as hosted on Tomcat'
}

Spring Boot Controller.java文件

@PostMapping("/Post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") 
MultipartFile file){ String Message=""; try .......(and so on)}

我的角度组件

<form [formGroup]="uploadForm" (ngSubmit) = "onSubmit()">
<input type="file" id="selectFile" formControlName="file1" name="selectFile"
(change)="fileEvent($event)"/>

<input type="submit" name="Submit"/>
</form>

Component.ts文件

fileEvent(e) {
 this.data = e.target.files[0];
}
omSubmit() {
  let headers: any = new Headers();
  headers.append('Content-type','undefined');
  let formData = new FormData();
  formData.append("selectFile",this.data);
  const req5 = new HttpRequest('POST','url as hosted on TOMCAT',formData,reportProgress: true,responseType: 'text'
  });
  return this.httpClient.request(req5).subscribe(e => {(
  console.log(e);
  )}
}

我在哪里出错?

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!
public ResponseEntity<String> handleFileUpload(@RequestParam("file")
@H_404_5@
 

          

解决方法

Chrome中网络下的错误

{ timeStamp: ......,status: 400
  error: 'Bad Request',message: 'Required request part 'file' is not present'
  path: 'url as hosted on Tomcat'
}

Spring Boot Controller.java文件

@PostMapping("/Post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") 
MultipartFile file){ String Message=""; try .......(and so on)}

我的角度组件

<form [formGroup]="uploadForm" (ngSubmit) = "onSubmit()">
<input type="file" id="selectFile" formControlName="file1" name="selectFile"
(change)="fileEvent($event)"/>

<input type="submit" name="Submit"/>
</form>

Component.ts文件

fileEvent(e) {
 this.data = e.target.files[0];
}
omSubmit() {
  let headers: any = new Headers();
  headers.append('Content-type','undefined');
  let formData = new FormData();
  formData.append("selectFile",this.data);
  const req5 = new HttpRequest('POST','url as hosted on TOMCAT',formData,reportProgress: true,responseType: 'text'
  });
  return this.httpClient.request(req5).subscribe(e => {(
  console.log(e);
  )}
}

我在哪里出错?

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!
{ timeStamp: ......,status: 400
  error: 'Bad Request',message: 'Required request part 'file' is not present'
  path: 'url as hosted on Tomcat'
}
@PostMapping("/Post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") 
MultipartFile file){ String Message=""; try .......(and so on)}
<form [formGroup]="uploadForm" (ngSubmit) = "onSubmit()">
<input type="file" id="selectFile" formControlName="file1" name="selectFile"
(change)="fileEvent($event)"/>

<input type="submit" name="Submit"/>
</form>
fileEvent(e) {
 this.data = e.target.files[0];
}
omSubmit() {
  let headers: any = new Headers();
  headers.append('Content-type','undefined');
  let formData = new FormData();
  formData.append("selectFile",this.data);
  const req5 = new HttpRequest('POST','url as hosted on TOMCAT',formData,reportProgress: true,responseType: 'text'
  });
  return this.httpClient.request(req5).subscribe(e => {(
  console.log(e);
  )}
}

原因

Chrome中网络下的错误

Spring Boot Controller.java文件

我的角度组件

Component.ts文件

我在哪里出错?

原因

public ResponseEntity<String> handleFileUpload(@RequestParam("file")
@H_404_5@
 

          

解决方法

Chrome中网络下的错误

{ timeStamp: ......,status: 400
  error: 'Bad Request',message: 'Required request part 'file' is not present'
  path: 'url as hosted on Tomcat'
}

Spring Boot Controller.java文件

@PostMapping("/Post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") 
MultipartFile file){ String Message=""; try .......(and so on)}

我的角度组件

<form [formGroup]="uploadForm" (ngSubmit) = "onSubmit()">
<input type="file" id="selectFile" formControlName="file1" name="selectFile"
(change)="fileEvent($event)"/>

<input type="submit" name="Submit"/>
</form>

Component.ts文件

fileEvent(e) {
 this.data = e.target.files[0];
}
omSubmit() {
  let headers: any = new Headers();
  headers.append('Content-type','undefined');
  let formData = new FormData();
  formData.append("selectFile",this.data);
  const req5 = new HttpRequest('POST','url as hosted on TOMCAT',formData,reportProgress: true,responseType: 'text'
  });
  return this.httpClient.request(req5).subscribe(e => {(
  console.log(e);
  )}
}

我在哪里出错?

喜欢与人分享编程技术与工作经验,欢迎加入编程之家官方交流群!
{ timeStamp: ......,status: 400
  error: 'Bad Request',message: 'Required request part 'file' is not present'
  path: 'url as hosted on Tomcat'
}
@PostMapping("/Post")
public ResponseEntity<String> handleFileUpload(@RequestParam("file") 
MultipartFile file){ String Message=""; try .......(and so on)}
<form [formGroup]="uploadForm" (ngSubmit) = "onSubmit()">
<input type="file" id="selectFile" formControlName="file1" name="selectFile"
(change)="fileEvent($event)"/>

<input type="submit" name="Submit"/>
</form>
fileEvent(e) {
 this.data = e.target.files[0];
}
omSubmit() {
  let headers: any = new Headers();
  headers.append('Content-type','undefined');
  let formData = new FormData();
  formData.append("selectFile",this.data);
  const req5 = new HttpRequest('POST','url as hosted on TOMCAT',formData,reportProgress: true,responseType: 'text'
  });
  return this.httpClient.request(req5).subscribe(e => {(
  console.log(e);
  )}
}

Chrome中网络下的错误

Spring Boot Controller.java文件

我的角度组件

Component.ts文件

我在哪里出错?

Java 2022/1/1 18:13:37 有756人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶