0

I am newbie to angularjs. I succeeded in making the fileuploader work and displaying the files uploaded. Now I want to remove the files which I do not want.

Here is how my upload and display works.

html file

 <div class="container-fluid">
    <error-display error-display-api="errorDisplayApi"></error-display>
    <div ng-controller="complianceItemDocumentcontroller">

        <div class="form-inline">
            <span class="btn btn-default">
                Add Photo
                <input ng-model="file"
                       onchange="angular.element(this).scope().file_changed(this)"
                       type="file" accept="image/*">
            </span>
            <button ng-click="removeFile()">Delete Photo</button>   
        </div>
        <div ng-repeat="images in document">
            <label name ="desscription" ng-bind ="images.Description"></label><br>
        </div>
    </div>
</div>

javascript file

app.controller('complianceItemDocumentcontroller', ['$scope', '$http',     function ($scope, $http)
{       
    var url = "http://localhost:/....";
    $http.get(url)
            .success(function (data, status, headers, config)
             {
                $scope.document = data;
             })
             .error(function (data, status, headers, config)
             {
                $scope.document = undefined;
             });        
    $scope.removeFile = function()
        {
            alert("delete");
        };
    $scope.file_changed = function(element)
        {
            $scope.$apply(function (scope)
            {
                var fd = new FormData();
                fd.append('file', element.files[0]);
                var urlpost = "http/.....";
                var req = { method: 'POST', url: urlpost, headers: { 'Content-    Type': undefined }, data: fd} 
                $http(req)
                .success(function (data, status, headers, config)
                {
                    alert("uploaded");
                })
                .error(function (data, status, headers, config)
                {
                    alert("fail");
                });
            });
        }
}]);

I should be able to select the images in the list and based on the selection of the file I should be able to call the related API to remove the document using the document ID. I am unable to figure out how to select a file and upon selected get the document ID. Then I will call the method through httppost and that will be deleting the file in the database. Also I should be able to display the images available as thumbnails. Currently it is just a plain list of names of files.

Thank you for your time and suggestions.

ramamoorthy_villi
  • 1,939
  • 1
  • 17
  • 40
  • I am able to get the Document ID but I keep getting the Http 405 Error when I try to do HttpDelete. Post and Get works fine. I have tried adding as mentioned here http://stackoverflow.com/questions/12521499/cors-support-for-put-and-delete-with-asp-net-web-api but still the delete fails. – anusha chanda Jul 08 '15 at 15:49
  • $scope.removeFile = function(documentId) { var urlpost = "http://localhost:7174/....documents/" + documentId + "/remove"; var req = { method: 'DELETE', url: urlpost}; $http(req) .success(function (data, status) { alert("deleted"); }). error(function (data, status) { alert("delete failed"); }); }; – anusha chanda Jul 08 '15 at 15:54
  • I see that the ID is coming from the html when clicked on delete link. I have removed the delete button and created a delete link beside each photo in the list. Http 405 error appears when a delete request is made. I have tried to make changes to webconfig file as mentioned in the above link. How do I overcome this http405 error? – anusha chanda Jul 08 '15 at 15:54
  • I fixed the issue with a workaround. Delete does not work for me so I have changed the WebAPI to HTTPPost and sending the documentId binded and deleting the image. – anusha chanda Jul 13 '15 at 18:18

0 Answers0