Click here to Skip to main content
15,886,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am facing an issue in mvc 4 web api .
I want to sent comma seprated image id like 1,2,3 and want to get all 3 images using mvc 4 web api.


i am using that code now

C#
public class ImageServiceController : ApiController
    {
        public HttpResponseMessage Get(string id)
        {
            try
            {
                var result = new HttpResponseMessage(HttpStatusCode.OK);
                String[] strArray = id.Split(',');
                int[] intArray = new int[strArray.Length];
                
               
                for (int i = 0; i < strArray.Length; i++)
                {
                    intArray[i] = int.Parse(strArray[i]);
                    String filePath = HostingEnvironment.MapPath("~/Images/" + intArray[i] + ".png");
                    FileStream fileStream = new FileStream(filePath, FileMode.OpenOrCreate);
                    Image image = Image.FromStream(fileStream);
                    MemoryStream memoryStream = new MemoryStream();
                    image.Save(memoryStream, ImageFormat.Png);
                    result.Content = new ByteArrayContent(memoryStream.ToArray());
                    result.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png");
                    fileStream.Close();
                    memoryStream.Dispose();
                }
                return result;
            }
            catch (Exception ex)
            {
                return new HttpResponseMessage(HttpStatusCode.NotFound);
            }
        }


Thanks in advance
Posted
Updated 1-Jun-14 23:21pm
v2
Comments
norbitrial 2-Jun-14 6:31am    
What is the problem with the code? Can you please provide us more information?

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