简体   繁体   English

将图像捕获照片从 Phone gap 传输到 C# asp.net Web Service

[英]Transfer image capture photo from Phone gap to C# asp.net Web Service

Below is my j query function uploadPicOne()下面是我的 j 查询函数 uploadPicOne()

        $(function() {
            var allVals = []; //for global check boxes
            $(document).on("click", ".click-action-for-event", function(e) {
        debugger;

                        //current i am calling this method for upload picture
                        uploadPicOne();

            })       
            });


        var uploadPicOne = function() {
            navigator.camera.getPicture(updateProfilePicService_one, onFail, {
                quality: 50,
                destinationType: navigator.camera.DestinationType.FILE_URI,
                encodingType: navigator.camera.EncodingType.JPEG,
                sourceType: navigator.camera.PictureSourceType.CAMERA
            });
        }

        var updateProfilePicService_one = function(fileUri) {
            SpinnerPlugin.activityStart("Loading...", { dimBackground: true });
            var options = new FileUploadOptions();
            options.fileKey = "image";
            options.fileName = fileUri.substr(fileUri.lastIndexOf('/') + 1);
            options.mimeType = "image/jpeg";
            options.params = {
                "status": "B2",
                "iTrainingId": $("#iTrainingId_currentprogramme").val(),
                "session_date": $("#iTrainingDate_currentprogramme").val(),
            };
            options.headers = {
                "X-Api-Key": localStorage.getItem("auth_key"),
            };
            options.chunkedMode = false;
            var ft = new FileTransfer();
            console.log(options);
            ft.upload(fileUri, base_url + "uploadpic", win, fail, options);   

        }

Below is my webservice not sure its work for phone gap以下是我的网络服务不确定它是否适用于电话间隙

        [WebMethod]
 public string uploadpic()
 {
     string msg = "";

     using (SqlConnection con = new SqlConnection(strConn))
     {
         SqlCommand cmd = new SqlCommand("App_Service", con);
         cmd.CommandType = CommandType.StoredProcedure;
         try
         {

             var request = HttpContext.Current.Request;
             IEnumerable<string> headers = request.Headers.GetValues("X-Api-Key");
             var auth_key = headers.FirstOrDefault();

             //  HttpPostedFile file = HttpContext.Current.Request.Files["image"];
             HttpPostedFile file = HttpContext.Current.Request.Files[0];
             string saveFile = file.FileName;
             file.SaveAs(Server.MapPath("/Trainer_Images/" + saveFile));

             cmd.Parameters.AddWithValue("@Paravalue", "14");
             cmd.Parameters.AddWithValue("@Value", saveFile);
             cmd.Parameters.AddWithValue("@Value1", auth_key);
             cmd.Parameters.AddWithValue("@Value2", "0");
             cmd.Parameters.AddWithValue("@Value3", "0");
             con.Open();
             cmd.ExecuteNonQuery();


             cmd.Dispose();
             con.Close();
             con.Dispose();
             //Context.Response.Write(JSONResult);
             //return d1.data;

            /// msg = "File uploaded";


         }
         catch (Exception ex)
         {
             msg = "Could not upload file: " + ex.Message;

         }
     }
     return msg;
 }

I need to know my web service is correct or wrong.我需要知道我的网络服务是正确还是错误。 I am not able to run my webservice also, my requirement is send captured image file to my asp.net web-service and save to database, please help me to achieve my requirement or any suggestion or any examples related my need.我也无法运行我的网络服务,我的要求是将捕获的图像文件发送到我的 asp.net 网络服务并保存到数据库,请帮助我实现我的要求或任何建议或任何与我的需要相关的示例。 The above jquery functions are working fine because the same app using into different application.上面的 jquery 函数工作正常,因为同一个应用程序用于不同的应用程序。

Today I have checked this code is not working through mobile showing loading after taking photo from mobile.今天我检查了此代码在从手机拍照后无法通过手机显示加载。

I think you are making asp.net web service (asmx).It needs ajax enabled to be called from JavaScript.我认为您正在制作 asp.net Web 服务 (asmx)。它需要启用 ajax 才能从 JavaScript 调用。 For your project i think you should use Asp.net mvc API check this article.对于您的项目,我认为您应该使用 Asp.net mvc API 检查这篇文章。 https://www.c-sharpcorner.com/article/uploading-image-to-server-using-web-api-2-0/ https://www.c-sharpcorner.com/article/uploading-image-to-server-using-web-api-2-0/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM