/// <summary>
        /// 上传头像
        /// </summary>
        public async Task <string> Post()
        {
            string       imageName;
            MysqlConnent myConnent = new MysqlConnent();

            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            Dictionary <string, string> dic = new Dictionary <string, string>();
            string root = HttpContext.Current.Server.MapPath("~/Image");//指定要将文件存入的服务器物理位置

            Debug.WriteLine(root);
            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            var provider = new MultipartFormDataStreamProvider(root);

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                List <string> fileName = new List <string>();

                // This illustrates how to get the file names.
                foreach (MultipartFileData file in provider.FileData)
                {                                                               //接收文件
                    Trace.WriteLine(file.Headers.ContentDisposition.FileName);  //获取上传文件实际的文件名
                    Trace.WriteLine("Server file path: " + file.LocalFileName); //获取上传文件在服务上默认的文件名
                    await Task.Delay(1000);

                    Save(file.LocalFileName, 77, 77);
                    fileName.Add(file.LocalFileName);
                }//TODO:这样做直接就将文件存到了指定目录下,暂时不知道如何实现只接收文件数据流但并不保存至服务器的目录下,由开发自行指定如何存储,比如通过服务存到图片服务器
                foreach (var key in provider.FormData.AllKeys)
                {//接收FormData
                    dic.Add(key, provider.FormData[key]);
                }
                imageName = fileName[0].Substring(fileName[0].Length - 45, 45);
                Debug.WriteLine(imageName);
                string account = dic["Account"];
                myConnent.MySqlWrite("INSERT INTO 图片表() VALUES('" + imageName + "','" + account + "','" + DateTime.Now.ToString("yyyyMMddHHmmss") + "','" + "0" + "','" + "0" + "','" + "暂无" + "','" + "0" + "','" + "暂无" + "','" + "0" + "','" + "0" + "','" + "0" + "','" + DateTime.Now.ToString("yyyyMMddHHmmss") + "')");
                // myConnent.MySqlHasRows("SELECT * FROM 路径表() ")
                myConnent.MySqlWrite("UPDATE 账号表 SET HeadImageName = '" + imageName + "' WHERE Account = '" + account + "'");
            }
            catch
            {
                throw;
            }

            return(imageName);
        }
Example #2
0
        /// <summary>
        /// 获取已关注的人的列表
        /// </summary>
        /// <param name="account"></param>
        /// <returns></returns>
        public ReturnMyFollow Get(string account)
        {
            MysqlConnent myConnent = new MysqlConnent();

            ReturnMyFollow returnModel = new ReturnMyFollow();

            try
            {
                List <User> tmpUserList = new List <Models.User>();
                //select * from info where name regexp 'ic'
                //like "%2%"

                List <string> accountList = myConnent.MySqlRead("SELECT * FROM 关注表 WHERE FollowerAccount ='" + account + "'", "WasFollowederAccount");

                if (accountList[0] != "error")
                {
                    foreach (string wasFollowederAccount in accountList)
                    {
                        User tmpUser = new User();
                        tmpUser.account      = wasFollowederAccount;
                        tmpUser.email        = myConnent.MySqlReadReturn("SELECT * FROM 账号表 WHERE Account ='" + wasFollowederAccount + "'", "email");
                        tmpUser.sex          = myConnent.MySqlReadReturn("SELECT * FROM 账号表 WHERE Account ='" + wasFollowederAccount + "'", "sex");
                        tmpUser.userName     = myConnent.MySqlReadReturn("SELECT * FROM 账号表 WHERE Account ='" + wasFollowederAccount + "'", "userName");
                        tmpUser.introduction = myConnent.MySqlReadReturn("SELECT * FROM 账号表 WHERE Account ='" + wasFollowederAccount + "'", "introduction");
                        tmpUserList.Add(tmpUser);
                    }

                    returnModel.result   = "true";
                    returnModel.userList = tmpUserList;
                    return(returnModel);
                }
                else
                {
                    returnModel.result = "error";
                    return(returnModel);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
                returnModel.result = "error";
                return(returnModel);
            }
        }
Example #3
0
        /// <summary>
        /// 接收图片
        /// </summary>
        /// <returns></returns>
        public async Task <string> Post()
        {
            MysqlConnent myConnent = new MysqlConnent();

            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            Dictionary <string, string> dic = new Dictionary <string, string>();
            string root = HttpContext.Current.Server.MapPath("~/File");//指定要将文件存入的服务器物理位置

            Debug.WriteLine(root);
            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            var provider = new MultipartFormDataStreamProvider(root);

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                List <string> fileName = new List <string>();

                // This illustrates how to get the file names.
                foreach (MultipartFileData file in provider.FileData)
                {                                                               //接收文件
                    Trace.WriteLine(file.Headers.ContentDisposition.FileName);  //获取上传文件实际的文件名
                    Trace.WriteLine("Server file path: " + file.LocalFileName); //获取上传文件在服务上默认的文件名
                    await Task.Delay(1000);
                }//TODO:这样做直接就将文件存到了指定目录下,暂时不知道如何实现只接收文件数据流但并不保存至服务器的目录下,由开发自行指定如何存储,比如通过服务存到图片服务器
            }
            catch
            {
                throw;
            }

            return("true");
        }