手机摄像头拍摄的照片上传(js .net)

参考:

https://developer.mozilla.org/zh-CN/docs/Web/API/FormData/Using_FormData_Objects

https://segmentfault.com/q/1010000011957065/

https://blog.csdn.net/qq_39327418/article/details/89212987

http://jqweui.com/

http://jqweui.com/download

前端js

后端.net(一般处理程序,ashx)

 

html

  <a href="javascript:;" class="btn btn-success btn-block" data-use="shuidian" data-useid="2"
           onclick="UploadFile('form1')">上传文件</a>

 

 <input type="file" accept="image/*" capture="camera" id="newimage" name="newimage" style="" >

js

function UploadFile(formName) {
            var formData = new FormData();
            var input = document.getElementById("newimage");
            var files = input.files;

            formData.append("aa", "123");

            for (var i = 0; i < files.length; i++) {
                formData.append("upfile[]", files[i]);
            }


            $.ajax({
                url: "WebService.ashx",
                type: "post",
                data: formData,
                processData: false,
                contentType: false,
                success: function (res) {
                    if (res) {
                        alert(res);
                    }
                },
                error: function (err) {
                    alert("网络连接失败,稍后重试", err.responseText);
                }

            })

        }

ashx

public void ProcessRequest(HttpContext context)
        {
            if (context.Request["aa"] == null)
            {
                return;
            }

            if (context.Request["aa"].ToString() != "123")
            {
                return;
            }

            if (context.Request.Files.Count == 0)
            {
                return;
            }

            string rtn = "Ok";

            string aa= string.Empty;
            //FileStream file = (HttpInputStream)context.Request.Files[0].InputStream;
            string fileName = string.Empty;
            string fileLength = string.Empty;
            string fileType = string.Empty;
            string path = string.Empty;

            try
            {
                aa= context.Request["aa"].ToString();
                //FileStream file = (HttpInputStream)context.Request.Files[0].InputStream;
                fileName = context.Request.Files[0].FileName;
                fileLength = context.Request.Files[0].ContentLength.ToString();
                fileType = context.Request.Files[0].ContentType;
                path = context.Server.MapPath(@"Files/" + fileName);

                context.Request.Files[0].SaveAs(path);
            }
            catch (Exception ex)
            {
                rtn = ex.Message + ":" + path;
            }


            context.Response.ContentType = "text/plain";
            context.Response.Write(rtn);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

 

posted on 2019-06-20 16:31 阿日斯兰 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/loge/p/11059593.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值