0

I want to extract the file through HTML and AngularJS to Java Spring with Hibernate. So, for example I've got in my HTML just:

<button type="button" class="btn btn-success btn-lg" ng-click="sendMail()">
<span class="glyphicon glyphicon glyphicon-send"></span> Wyślij
</button>
<input type="file" file-upload multiple name="file"/>   
<button ng-click="add()">Add</button>

And i guess that's all for HTML.

JS file:

$scope.sendMail = function(){  
 $scope.emailData = new EmailData();
 $scope.emailData.to = "[email protected]";       
 $scope.emailData.from = "[email protected]";
 $scope.emailData.subject = "Sending maila";
 $scope.emailData.type = "Sending failure";
 $scope.emailData.title = $scope.data.title;
 $scope.emailData.descriptMail = $scope.data.description;
 $scope.emailData.description = "Chrome 5.4.0";

 $http.post("sendemail", $scope.emailData, {headers: {'Content-Type':'application/json'} })
 .then(function (response) {         
    $scope.succes =  true;
 },
function(fail) {
    $scope.error = true;
});

}

So, how can I get this file which i drop and click add? I wanted, just like with other datas take $scope.emailData.attachement = ""; to use this in my Spring file.

Example:

in js I've got $scope.emailData.description = "Chrome 5.4.0"; and I can get it by spring: private String description; and stuff with getters and setters

and then I can use it.

I'm not good in Spring and backend (yet), so that's why I am asking you

8
  • Are you attempting to send an email or upload a file? Commented Aug 25, 2017 at 11:33
  • 1
    Do you have any code sending to the server yet? If not, you'll probably want to familiarize yourself with the $http service: docs.angularjs.org/api/ng/service/$http#post Commented Aug 25, 2017 at 11:49
  • 1
    And here's a SO answer showing how to post form data (your email properties like to, from, subject, etc) and the file: stackoverflow.com/a/25264008/769971 Commented Aug 25, 2017 at 11:51
  • 1
    In the SO post I linked, they're using a FormData object. FormData allows you to append a file as well as regular form data: developer.mozilla.org/en-US/docs/Web/API/FormData/… Commented Aug 25, 2017 at 11:59
  • 1
    I would recommend adding your angular code that talks to your Java side to your original post since that's the important part with respect to your problem. Commented Aug 25, 2017 at 12:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.