Bonjour, je teste l'upload de fichier en webservices avec angular.

sur mon backend avec spring boot avec le logiciel advanced REST, l'upload de fichier fonctionne correctement,
voici une image:

Nom : post_ok.png
Affichages : 4231
Taille : 27,9 Ko

Voici mon frontend :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 
onFileSelected(event){
    this.selectedFile = event.target.files[0];
  }
 
  onUpload(){
    console.log("onUload .....");
    console.log(this.selectedFile);
 
    const fd = new FormData();
    fd.append('fichier',this.selectedFile,this.selectedFile.name);
    console.log("resultat FD ====>");
    console.log(fd);
    this.http.post("http://localhost:8181/upload/",fd,{headers:{'Content-Type': 'multipart/form-data'}}).subscribe(
      res => {
        console.log(res);
      }
    );
 
  }
Quand je tentes de le faire côté backend sans passer par postman j'obtient une erreur en appelant la fonction onUpload:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
POST http://localhost:8181/upload/ net::ERR_CONNECTION_RESET
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
2019-08-03 07:46:16.707 ERROR 2356 --- [nio-8181-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found] with root cause
voici mon REST controller:

Code java : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
@RestController
public class TeleverserService
{
	@RequestMapping(value = "/upload",
			method = RequestMethod.POST,
			consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
 
	public String fileUpload(@RequestParam("fichier") MultipartFile file) throws IOException
	{
        System.out.println("reception du fichier uploader");
        System.out.println(file.getOriginalFilename());
		File convertFile = new File("C:/Users/aker/Desktop/upload/" + file.getOriginalFilename());
		convertFile.createNewFile();
 
		try (FileOutputStream fout = new FileOutputStream(convertFile))
		{
            System.out.println(fout);
			fout.write(file.getBytes());
		}
		catch (Exception exe)
		{
			exe.printStackTrace();
		}
		return "test upload .... ??";
	}
 
}

merci d'avance pour la réponse