zoukankan      html  css  js  c++  java
  • 微信小程序上传文件


    wx.chooseImage({ count: 1, // 默认9 sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有 sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有 success: function (res) { // 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片 var tempFilePaths = res.tempFilePaths console.log(tempFilePaths[0]) wx.uploadFile({ url: 'https://gh.ydfos.com/wxfileUplad/Post', //仅为示例,非真实的接口地址 filePath: tempFilePaths[0], name: 'file', formData:{ 'address': 'jinhua', 'name':'zjh' }, success: function(res2){ console.log(res2); var data = res2.data console.log(data); //do something } }) } } )


    服务端代码
    var logCfg = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "config/log4net.config");
                XmlConfigurator.ConfigureAndWatch(logCfg);
                var logger = LogManager.GetLogger("log");
    
                try
                {
    
                    logger.Info("files:" + Request.Files.Count);
                    logger.Info("filename:" + Request.Files[0].FileName);
    
                    
                    string filepath = Server.MapPath("/upload/");
                    Stream sin = Request.InputStream;
    
                    string name = Request.QueryString["name"];
                    string fileExt = Path.GetExtension(Request.Files[0].FileName).ToLower();
                    string fileName = Guid.NewGuid().ToString() + fileExt;
                    Request.Files[0].SaveAs(filepath + fileName);
    
    
    
                    logger.Info("name:" + Request.Form["name"] + ";address:" + Request.Form["address"]);
    
                    return Json(new { success="ok"}, JsonRequestBehavior.AllowGet);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                    return Json(new { success = "fail" }, JsonRequestBehavior.AllowGet);
                }
    

      

      

  • 相关阅读:
    打印杨辉三角形
    Java中的基本数据类型
    C语言网上点餐系统1.0
    C语言中常用的输入和输出函数
    ubantu忘记登录密码怎么办?(ubantu16.04)
    Linux常用服务器构建-samba(ubantu)
    Vue为文件目录设置别名
    css内容占满全屏
    Vue中引入了better-scroll后 页面上的点击事件不生效了
    javascript中获取dom元素高度和宽度的方法
  • 原文地址:https://www.cnblogs.com/jyzjh/p/6242508.html
Copyright © 2011-2022 走看看