0

I have a Web Api that shows some datas. Now, i have to Show a image, that is stored on a Oracle DB... in Oracle DB is everything ok and the Stored Procedure brings me a "Long Raw". Actualy the result of FOTO on the controller is empty [{"ISUSPID":0,"FOTO":""}], even when on DB brings me the image... The question is what i am doind wrong, thats the FOTO is empty on Json ???

This is my class [FotoEnvolvido]:

using System;
using System.ComponentModel.DataAnnotations;


namespace WebApiApp.Models
{
    public class FotoEnvolvido
    {
        [Key]
        public Int32 ISUSPID { get; set; }
        public byte[] FOTO { get; set; }
    }
}

This is my Controller:

[HttpGet]
        [Route("Foto")]
        public IEnumerable<FotoEnvolvido> GetFoto(Int32 isuspid)
        {

            DataSet lretorno = new DataSet();

            string connectionString = GetConnectionString();
            using (OracleConnection connection = new OracleConnection())
            {
                connection.ConnectionString = connectionString;

                OracleDataReader reader = null;
                OracleCommand cmd = new OracleCommand();
                cmd.Connection = connection;
                cmd = new OracleCommand("MOBILE.XAPIMANDADOMOBILE.BUSCAFOTO", connection);
                cmd.CommandType = CommandType.StoredProcedure;

                //variáveis entrada            
                cmd.Parameters.Add(new OracleParameter("isuspid", isuspid));

                //variáveis de saida          
                cmd.Parameters.Add(new OracleParameter("oretorno", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;

                connection.Open();
                cmd.ExecuteNonQuery();

                reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

                //CRIO A LISTA
                lretorno.Load(reader, LoadOption.OverwriteChanges, "BUSCAFOTO");
                connection.Close();
                connection.Dispose();


                //CARREGO O DATASET E TRANSFORMO PARA IENUMERABLE E RETORNO SEUS VALORES PRO JSON
                return lretorno.Tables[0].AsEnumerable().Select(row => new FotoEnvolvido
                {
                    FOTO = (byte[])(row["FOTO"]),
                });



            }
        }
Mcfer
  • 194
  • 1
  • 4
  • 15
  • you haven't actually asked a question. SO is a Q&A site, so you should ask a Question if you want us to provide an answer. – Jason Jul 12 '16 at 15:27
  • @Jason The question is what i am doind wrong, thats the FOTO is empty on Json??? – Mcfer Jul 12 '16 at 15:30
  • http://stackoverflow.com/questions/19005991/webapi-how-to-handle-images – granadaCoder Jul 12 '16 at 16:05
  • @granadaCoder I am a little bit newbie, but all of this examples the image is downloaded for the device...i don´t want to do this... Or its not possible ? I just want to show in a page... just a stream! Don´t want to put in a path folder. – Mcfer Jul 12 '16 at 16:29

0 Answers0