2017-03-28 3 views
2

Ich möchte ein Bild in das Dateisystem hochladen. So verwende ich Multi-Teil-Datei-Upload mit Spring-Boot. Und auch ich benutze Advance Rest Client (Chrome) Werkzeug zu POSTMulti Teil Datei. Aber ich habe einen Fehler, obwohl ich keinen Inhaltstyp angegeben habe org.apache.tomcat.util.http.fileupload.FileUploadException: Die Anfrage wurde abgelehnt, weil keine Multipart-Grenze gefunden wurde.SpringBoot einfacher mehrteiliger Datei-Upload mit Advanced Rest-Client (Chrome)

Hier Code meine Ruhe Controller,

@RestController 
public class StringController { 
@RequestMapping(value="/upload", method=RequestMethod.POST) 
public @ResponseBody String singleSave(@RequestParam("file") MultipartFile file){ 

    String fileName = null; 
    if (!file.isEmpty()) { 
     try { 
      fileName = file.getOriginalFilename(); 
      byte[] bytes = file.getBytes(); 
      BufferedOutputStream buffStream = 
        new BufferedOutputStream(new FileOutputStream(new File("F:/" + fileName))); 
      buffStream.write(bytes); 
      buffStream.close(); 
      return "You have successfully uploaded " + fileName; 
     } catch (Exception e) { 
      return "You failed to upload " + fileName + ": " + e.getMessage(); 
     } 
    } else { 
     return "Unable to upload. File is empty."; 
    } 
    } 
} 

Screenshot (advance Rest-Client-Tool)

enter image description here

Fehler

{ "timestamp": 1490678908517, "status": 500, "error": "Internal Server Error", "exception": "org.springframework.web.multipart.MultipartException", "message": "Could not 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", "path": "/upload" }

Antwort

2

Das Problem ist aus Voraus Rest Client in Ihrer Anfrage. Es funktioniert gut im Briefträger. Das Bild wird hochgeladen. Versuchen Sie es mit Postboten, Sie werden es bekommen.

+0

yep bruder Es hat funktioniert. Danke für Ihre freundliche Antwort. Aber darf ich wissen, warum es im Voraus nicht funktioniert, Restklient? – Narendhran