Пример #1
0
        public dynamic UploadFile()
        {
            HttpResponseMessage response = new HttpResponseMessage();
            var  httpRequest             = HttpContext.Current.Request;
            long PropertyId = Convert.ToInt64(HttpContext.Current.Request.Form["PropertyId"]);

            if (httpRequest.Files.Count > 0)
            {
                var docfiles = new List <string>();
                foreach (string file in httpRequest.Files)
                {
                    var    postedFile = httpRequest.Files[file];
                    string fileName   = "Rent_" + DateTime.Now.ToString("yyyyMMddHHmmssfff") + ".jpg";
                    var    filePath1  = HttpContext.Current.Server.MapPath("~/RentPropertyFiles/" + fileName);
                    Stream strm       = postedFile.InputStream;
                    Utilities.Compressimage(strm, filePath1, postedFile.FileName);
                    _rent.SaveFile(new PropertyFileModel()
                    {
                        PropertyId = PropertyId, FileName = fileName
                    });
                }
                response = Request.CreateResponse(HttpStatusCode.Created, docfiles);
            }
            else
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest);
            }
            return(response);
        }