views:

11

answers:

0

maybe this is obvious but for some reason i can't find the answer on google. i'm simply trying to implement the cool ajax uploader with my ASP NET MVC app. i've created an action on my controller to successfully receive the post of the image via ajax, but once i'm in my action function on my controller, how do i now save this data into the actual image on my server? i imagine the code should do something like 1) take the posted content and create an buffer 2) pass the buffer to a new image object 3) save the image to disk. easy?

EDIT: figured it out.. this code seems to work:

FileStream log = new FileStream("C:\pic.png",FileMode.OpenOrCreate);

byte[] buffer = new byte[Request.ContentLength]; int c; while ((c = Request.InputStream.Read(buffer, 0, buffer.Length)) > 0) { log.Write(buffer, 0, c); } log.Close();