Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hej
im doing drag and drop image box's ,
with js ,and preview them which all work. but to save the image it self where there is no asp image , or something like file upload
i can save it as a file on server but im trying to save it to db

What I have tried:

C#
public void ProcessRequest(HttpContext context)

    {
        System.Diagnostics.Debugger.Break();
        context.Response.ContentType = "image/JPEG";


        System.Diagnostics.Debugger.Break();
        string dirFullPath = HttpContext.Current.Server.MapPath("~/MediaUploader/");
        string[] files;
        int numFiles;
        files = System.IO.Directory.GetFiles(dirFullPath);
        numFiles = files.Length;
        numFiles = numFiles + 1;


        string str_image = "";

        foreach (string s in context.Request.Files)
        {
            HttpPostedFile file = context.Request.Files[s];
            string fileName = file.FileName;
            string fileExtension = file.ContentType;


            if (!string.IsNullOrEmpty(fileName))
            {

                fileExtension = Path.GetExtension(fileName);
                str_image = "MyPHOTO_" + numFiles.ToString() + fileExtension;
                //string pathToSave = HttpContext.Current.Server.MapPath("~/MediaUploader/") + str_image;
                //file.SaveAs(pathToSave);
            }
        }
        context.Response.Write(str_image);
    }
Posted
Updated 28-Sep-18 23:46pm
v2

1 solution

C#
WebClient wc = new WebClient();
                   byte[] bytes = wc.DownloadData("Your URL" + ImageA.Remove(ImageA.IndexOf('\"')));
                   MemoryStream ms = new MemoryStream(bytes);
                   System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900