public HttpResponseMessage Post(BoxedString contact)
        {
            String a;

            var response = Request.CreateResponse <BoxedString>(System.Net.HttpStatusCode.Created, contact);
            // response.Headers.Add("Access-Control-Allow-Origin", "*");
            var base64Data = Regex.Match(contact.Text, @"data:image/(?<type>.+?),(?<data>.+)").Groups["data"].Value;

            byte[] bytes = Convert.FromBase64String(base64Data);

            Image image;

            using (ImagePocketEntities1 database = new ImagePocketEntities1())
            {
                using (MemoryStream ms = new MemoryStream(bytes))
                {
                    var numb = database.ImagesPathes.Count() + 1;
                    image = Image.FromStream(ms);
                    var newpath = @"~/Photoes/newimage_" + Convert.ToString(numb) + ".png";
                    image.Save(string.Format(@"C:\Users\Андрій\Documents\Visual Studio 2013\Projects\MvcApplication4\MvcApplication4\Photoes\newimage_{0}.png", Convert.ToString(numb)));
                    image.GetThumbnailImage(640, 320, null, new IntPtr()).Save(String.Format(@"C:\Users\Андрій\Documents\Visual Studio 2013\Projects\MvcApplication4\MvcApplication4\Photoes\newimagePreview_{0}.png", Convert.ToString(numb)));
                    database.ImagesPathes.Add(new ImagesPathes {
                        Path = newpath, ID = numb
                    });
                    database.SaveChanges();
                }
            }


            return(response);
        }
Example #2
0
        public HttpResponseMessage Post()
        {
            /*string filePath = @"c:/test/thelast2.mht",
             *  url2 = "http://stackoverflow.com/questions/10412691/file-api-not-working-with-blob-in-google-chrome-extension";
             * bool result = false;
             * CDO.Message msg = new CDO.Message();
             * ADODB.Stream stm = null;
             * try
             * {
             *  msg.MimeFormatted = true;
             *  msg.CreateMHTMLBody(url2, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
             *  stm = msg.GetStream();
             *  stm.SaveToFile(filePath, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
             *  msg = null;
             *  stm.Close();
             *  result = true;
             * }
             * catch
             * { throw; }*/
            var x = Request.Content.ReadAsStringAsync();

            x.Wait();

            //var data = System.Text.Encoding.UTF8.GetString(x.Result);
            using (ImagePocketEntities1 database = new ImagePocketEntities1())
            {
                var numb    = database.MhtmlPages.Count() + 1;
                var newpath = String.Format(@"~/Photoes/newpage_{0}.mht", Convert.ToString(numb));
                database.MhtmlPages.Add(new MhtmlPages {
                    PagePath = newpath, ID = numb
                });
                database.SaveChanges();

                File.WriteAllText(String.Format(@"C:\Users\Андрій\Documents\Visual Studio 2013\Projects\MvcApplication4\MvcApplication4\Photoes\newpage_{0}.mht", Convert.ToString(numb)), x.Result);
            }



            var response = Request.CreateResponse <string>(System.Net.HttpStatusCode.Created, x.Result);

            return(response);

            return(null);
        }