1

i have a input tag File mode in my html. but i dont know how to send it to the server. Is there any way to send the image path as "/Image/img.jpg" (image is the folder that i want to save the images) from angularjs. Because am getting the Image Description and the imageLocation as well. the Location and Descriptions are passing correctly to my asp.net web api controller. But the image path is always null. i tried lots of example. but its not helped me. all the tutorial refering only the uploading part. i need to send the Descriptions and Location also. will please any one help me to solve this problem?

My Html

  <input class="form-control" type="text" value="Image Name" id="example-text-input" ng-model="Description">
  <input type="file" fd-input />
  <select ng-model="Location" ng-selected="Location" class="form-control" id="Location" >
   <button type="button" class="btn btn-info" ng-click="AddImage()">Save </button>

Angular Controller

 $scope.AddImage= function () {


        var dataObj = {
            Id: $scope.Id,
            Description: $scope.Description,
           // Path: $scope.Path,
            Location: $scope.Location,

        };

        var request = $http({
            method: 'POST',
            url: urls.api + 'Banner/AddImage',
            //data: JSON.stringify(dataObj)
            data: dataObj

        }).success(function (data, status) {
            alert('saved succesfully');
        })
Manojkanth
  • 1,071
  • 11
  • 27
  • $scope.path is not assigned in code, do you want to send client selected file path to server? – hvojdani Apr 05 '17 at 06:12
  • @tomcater its better if i can send the path that i want to save the db. if it is not possible. its ok to send the client selected file path. But i need a solution for this. am trying it more than 4 days. please help me brother. – Manojkanth Apr 05 '17 at 06:16
  • so get path from user by a input, or set a static value for it in dataObj creation. – hvojdani Apr 05 '17 at 06:20
  • can you please provide the code for that. am new to angular. please – Manojkanth Apr 05 '17 at 06:21
  • just use an input like used for Description, but for sending file content search SO for samples – hvojdani Apr 05 '17 at 06:31

1 Answers1

0

You need to follow this links

Angular File Upload : https://stackoverflow.com/a/25264008/1365663

Save multipart Form data in API : https://stackoverflow.com/a/28370216/1365663

Community
  • 1
  • 1
Jignesh Variya
  • 1,869
  • 16
  • 12