如何将带有图像路径的表单的详细信息保存到sqlserver和数据库中的图像中 [英] How to save details of a form with an image path into a sqlserver and the image in the database

查看:70
本文介绍了如何将带有图像路径的表单的详细信息保存到sqlserver和数据库中的图像中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够将表单发送到我的sqldatabase并将图像保存到文件夹和数据库中的路径



我有什么试过:



i want to be able to send the form into my sqldatabase and save the image in a folder and the path in the database

What I have tried:

.directive("fileInput",function($parse){
                return {
                    restrict: "A",
                    link: function (scope,elem,attrs) {
                        elem.bind("change", function () {
                            $parse(attrs.fileInput).assign(scope, elem[0].files);
                            scope.$apply();
                        });
                    }
                }
            })
.controller("imageUploadPracticeController", function ($scope,$http,$timeout) {
                var vm = this;
                vm.loading = false;
                vm.msg = false;
                vm.error = false;
               // read();

                vm.imageUpload = function (event) {
                    var files = event.target.files;//filelist object
                    var file = files[files.length - 1];
                    vm.file = file;
                    var reader = new FileReader();
                    reader.onload = vm.imageIsLoaded;
                    reader.readAsDataURL(file);
                }
                vm.imageIsLoaded = function (e) {
                    $scope.$apply(function () {
                        vm.step = e.target.result;
                    });
                }

                vm.btnUpload = function () {
                    vm.loading = true;
                    var request = $http({
                        url: '../services/svImageUpload.asmx/insert',
                        method: 'POST',
                        data: { city: vm.City, country: vm.Country, flag: vm.file.name },
                        //transformRequest:angular.identity,
                        headers: {'content-type':undefined}
                    });
                    request.then(function (response) {
                        read();
                        vm.loading = false;
                        vm.error = false;
                        vm.hurray = response.data;
                        vm.msg = true;
                    }, function (error) {
                        vm.error = true;
                        vm.error = error.data;
                        vm.loading = false;
                        vm.msg = false;
                    });
                    //console.log(vm.City + ' ' + vm.Country + ' ' + vm.file.name);
                }
                var read = function () {
                    var request = $http("../services/svImageUpload.asmx/GetAllFiles")
                                  .then(function (response) { vm.imgUploads = response.data; });
                }
                vm.closeSuccessMsg = function () {
                    vm.loading = false;
                    vm.msg = false;
                    vm.error = false;
                    $("#txtCity").val('');
                    $("#txtCountry").val('');
                }
                vm.closeErrorMsg = function () {
                    vm.loading = false;
                    vm.msg = false;
                    vm.error = false;
                    $("#txtCity").val('');
                    $("#txtCountry").val('');
                }
            });







[WebMethod]
        public string insert(string city,string country,string flag)
        {
            try
            {
                using(SqlConnection conn =new SqlConnection(clsMain.sqlconnstring))
                {
                    conn.Open();
                    SqlCommand cmd = new SqlCommand("spInsertUploadPicture", conn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@city", city);
                    cmd.Parameters.AddWithValue("@country",country);
                    cmd.Parameters.AddWithValue("@imgpath", string.Format("../imageUploads/{0}",flag));
                    cmd.ExecuteNonQuery();
                    return "Record Uploaded Successfully";
                }
            }
            catch (Exception)
            {
                
                throw;
            }
        }

推荐答案

parse){
return {
restrict:一个,
链接:function(scope,elem,attrs){
elem.bind(change,function(){
parse){ return { restrict: "A", link: function (scope,elem,attrs) { elem.bind("change", function () {


parse(attrs.fileInput) ).assign(scope,elem [0] .files);
范围。
parse(attrs.fileInput).assign(scope, elem[0].files); scope.


apply();
});
}
}
})
.controller(imageUploadPracticeController,函数(
apply(); }); } } }) .controller("imageUploadPracticeController", function (


这篇关于如何将带有图像路径的表单的详细信息保存到sqlserver和数据库中的图像中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆