2016-04-11 19 views
0

$ resource kullanarak RESTful web hizmeti (yaylı önyükleme ile çalışıyor) ile iletişim kurmak için AngularJS kullanıyorum. Bazı dosya yüklemek ve aynı çok parçalı sonrası isteği dahilinde form alanları göndermeye çalışıyorum ama aşağıdaki hatayı alıyorum: Burada

<form method="post" enctype="multipart/form-data" ng-submit="submit()"> 
    <table> 
    <tr><td>File to upload:</td><td><input type="file" name="file" ng-model="form.file"/></td></tr> 
    <tr><td>Name:</td><td><input type="text" name="name" ng-model="form.name"/></td></tr> 
    <tr><td></td><td><input type="submit" value="Upload" /></td></tr> 
    </table> 
</form> 

görünümüdür: Burada

"Unsupported Media Type" exception: "org.springframework.web.HttpMediaTypeNotSupportedException" message: "Content type 'application/xml' not supported" path: "/study/upload" status: 415

benim bakış şeklidir kontrol:

$scope.submit=function(){ 
    GalleryService.upload({file: $scope.form.file, name: $scope.form.name}, function(data) { 
     console.log("Success ... " + status); 
    }, function(error) { 
     console.log(error); 
    }); 
} 

gallery.service:

(function() { 

'katı kullan';

açısal .module ('ekellsApp') .factory ('GalleryService', GalleryService);

fonksiyonu GalleryService ($ kaynak restApi) {

return $resource(restApi.url + '/study/:action', {},{ 
    save: {method: 'POST', params: {action: 'save'}}, 
    getAll: {method: 'GET', params: {action: 'getAll'},isArray:true}, 
    upload: {method: 'POST', params: {action: 'upload'}, transformRequest: angular.identity,headers: { 'Content-Type': undefined }} 


}); 

}

})(); Burada

ve

DİNLENME denetleyicisi geçerli:

@RequestMapping(value = "/upload",method = RequestMethod.POST,headers = "content-type=multipart/*") 
public String handleFileUpload(@RequestParam("name") String name, 
           @RequestParam("file") MultipartFile file, 
           RedirectAttributes redirectAttributes) { 
    if (name.contains("/")) { 
     redirectAttributes.addFlashAttribute("message", "Folder separators not allowed"); 
     return "redirect:upload"; 
    } 
    if (name.contains("/")) { 
     redirectAttributes.addFlashAttribute("message", "Relative pathnames not allowed"); 
     return "redirect:upload"; 
    } 

    if (!file.isEmpty()) { 
     try { 
      BufferedOutputStream stream = new BufferedOutputStream(
        new FileOutputStream(new File("user/bouhuila/" + name))); 
      FileCopyUtils.copy(file.getInputStream(), stream); 
      stream.close(); 
      redirectAttributes.addFlashAttribute("message", 
        "You successfully uploaded " + name + "!"); 
     } 
     catch (Exception e) { 
      redirectAttributes.addFlashAttribute("message", 
        "You failed to upload " + name + " => " + e.getMessage()); 
     } 
    } 
    else { 
     redirectAttributes.addFlashAttribute("message", 
       "You failed to upload " + name + " because the file was empty"); 
    } 

    return "redirect:upload"; 
} 

cevap

0

Ben

GalleryService.upload 

ne yaptığını göremiyorum, ama gerçekten sunucuya formu göndermediği gibi görünüyor ama sadece bazı alanlar. Bu durumda, aldığınız hatayı açıklayabilecek

kullanılmayacaktır.

Tarayıcınızdaki geliştirici araçlarına bir göz atın, bu istek aslında sunucunuza gönderilir ve hangi içerik türünü kullanıyordur?

İlgili konular