Пример #1
0
        public async Task <HttpResponseMessage> Save()
        {
            //todo
            if (!Request.Form.Files.Any())
            {
                UploadImage model = new UploadImage();
                foreach (string kvp in Request.Form.Keys)
                {
                    PropertyInfo pi = model.GetType().GetProperty(kvp, BindingFlags.Public | BindingFlags.Instance);
                    if (pi != null)
                    {
                        pi.SetValue(model, Request.Form[kvp], null);
                    }
                }

                foreach (var formFileTemp in Request.Form.Files)
                {
                    if (formFileTemp.Length > 0)
                    {
                        var filePath = Path.GetTempFileName();

                        using (var stream = System.IO.File.Create(filePath))
                        {
                            await formFileTemp.CopyToAsync(stream);
                        }
                    }
                }
            }

            return(new HttpResponseMessage(HttpStatusCode.OK));
        }