none
Web API Response Display the Image RRS feed

  • Question

  • Hi , Im not able to see the Image in the Http Response ,Below is my code . Can anyone suggest on how to download the Image . Thanks in Advance . 

    [HttpGetAttribute]

    public HttpResponseMessage Download(Guid Id)

    { DbConnection db = new DbConnection();

     if (Id == Guid.Empty) { throw new HttpResponseException(HttpStatusCode.NotFound); }

    var TestQuery = db.tblTest.Where(P => P.TestID == (Id)) .Select(x => x.Photo).Single();


    var response = new HttpResponseMessage(HttpStatusCode.OK);
            {

                response.Content = new PushStreamContent((outputStream, httpContent, transpContext)
                     =>
                     {
                         using (outputStream)
                         {
                             using (Stream StrContent = new MemoryStream(TestQuery))
                             {
                                StrContent.CopyTo(outputStream, totalLength);

                             }
                         }

                     }, "Image/png");

            };

            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName =  "PhotoName.png"
            };
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("Image/png");
            return response;

        }


    • Moved by CoolDadTx Thursday, September 6, 2018 5:21 PM ASP.NET related
    Thursday, September 6, 2018 4:53 PM

All replies