zoukankan      html  css  js  c++  java
  • WebService 客户端上传图片,服务器端接收图片并保存到本地

    需求:如题,C#本地要调用Webservice接口,上传本地的照片到服务器中;

    参考:客户端: https://blog.csdn.net/tiegenZ/article/details/79927670

            服务端:   https://www.cnblogs.com/zzzili/archive/2012/12/16/6662668.html

           服务端接收的图片是base64编码的字节流:

      [WebMethod(Description = "上传图片")]
            public string getImageByte(Byte[] getByte)
            {
                string savaImageName = null;
                try
                {
                    DateTime dt = DateTime.Now;
                    string sFile = dt.ToShortDateString().ToString();//2005/11/5
                    String file = "/images/" + sFile;//   /images/2005/11/5
                    if (Directory.Exists(Server.MapPath(file)) == false)//如果文件不存在 则创建
                    {
                        Directory.CreateDirectory(Server.MapPath(file));
                    }
                    savaImageName = file + "/" + dt.ToFileTime().ToString() + ".png";//127756416859912816
                    FileStream fs = new FileStream(Server.MapPath(savaImageName), FileMode.Create, FileAccess.Write);
                    fs.Write(getByte, 0, getByte.Length);
                    fs.Flush();
                    fs.Close();
                }
                catch (Exception e)
                { }
                return savaImageName;
    
            }

        客户端直接添加服务引用,调用相关方法:

           

    string strFilePath = @"C:UsersAdministratorDesktop2.jpg";    
                    FileInfo fi = new FileInfo(strFilePath);
                    if (File.Exists(strFilePath))   
                    {
                        byte[] b = new byte[fi.Length];
                        System.IO.FileStream fs = fi.OpenRead();
                        fs.Read(b, 0, Convert.ToInt32(fi.Length));
                        WebReference.AppWebService ss = new WebReference.AppWebService();
                        string sr= ss.getImageByte(b);
    
                    }
  • 相关阅读:
    centos 6 安装
    DNS介绍
    Saltstack远程执行(四)
    Saltstack数据系统Grains和Pillar(三)
    array_multisort 二维数组排序
    jqgit...
    Redis 创建多个端口 链接redis端口
    百度商桥回话接口
    加ico
    redis 新开端口号
  • 原文地址:https://www.cnblogs.com/NetNotes/p/12787421.html
Copyright © 2011-2022 走看看