danialfarid / ng-file-upload

Lightweight Angular directive to upload files with optional FileAPI shim for cross browser support
MIT License
7.87k stars 1.6k forks source link

Problem with 415 error - cant do nothing #2039

Closed kapeeeek closed 6 years ago

kapeeeek commented 6 years ago

hi, I've got a new problem with my ng-file-upload app. I am creating email sender with attachment (angularJS + Java Spring).

Js code:

$scope.uploadFiles = function (event) {
        $scope.file = event.target.files[0];
    };
    $scope.sendEmailAttachment= function(){ 
        $scope.emailData = new EmailData();
        $scope.emailData.to = "sample1@gmail.com";
        $scope.emailData.from = "sample2@gmail.com";
        $scope.emailData.subject = "My subject";
        $scope.emailData.type = "ERROR";
        $scope.emailData.title = $scope.data.topic;
        $scope.emailData.description = $scope.data.description;
        $scope.emailData.template = "templateSender";   

        Upload.upload({
            method : 'POST',
            url : 'sendemail/attachment',
            headers: {
                'Content-Type': undefined
            },
            data : $scope.emailData,
            file : $scope.file
        }).success(function(response) {
            console.log("Success");
        }).error(function(error) {
            console.log("Error");
        });
    }

My java controller:

@RequestMapping(value = "/attachment", method = RequestMethod.POST)
public EmailStatus sendEmailAttach(@RequestBody EmailData emailData, @RequestParam("file") MultipartFile file) {
        return emailSenderAttachment.sendDataAttach(emailData, file);
    }

I've got error:

"status":415,"error":"Unsupported Media Type"

"Content type 'multipart/form-data;boundary=----WebKitFormBoundaryDjCedKgOWbfrh1lb;charset=UTF-8' not supported"

Someone can help me?

kapeeeek commented 6 years ago

Never mind, sorry but I resolved it :D

parmindersingh1 commented 6 years ago

i am getting same issue how did you fix it?