This is a migrated thread and some comments may be shown as answers.

Can't upload differents formats of image in a row template grid

2 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Juan
Top achievements
Rank 1
Juan asked on 21 Oct 2016, 12:16 PM

Can anyone help me with this issue.

I only can upload image in PNG format, but when i uplaod an image in JPG or GIF format the grid doesn't show me anything.

I try to convert JPG to PNG but is the same and don't show anything.

Any suggest of how can i do this.

This is my code example:

This is my grid in view:

@(Html.Kendo().Grid<TelerikMvcApp4.Models.PublicacionImagenModel>()
    .Name("grid")
    .HtmlAttributes(new { style = "height:335px;" })
    .Columns(columns =>
    {
        columns.Template(e => { }).ClientTemplate(" ").Width(140).Title("Imagen").HtmlAttributes(new { style = "height:40px" });
        columns.Command(command => command.Destroy()).Width(110);
    })
    //.AutoBind(false)
    .ClientRowTemplate(
        "<tr id='a' data-uid='#: uid #'>" +
            "<td class='photo'>" +
            "<img src='data:image/png;base64,#: imagen64 #' alt='#: data.Puim_clave_pub #' style='width: 180px; height:100px;'/>" +
            "</td>" +
         "<td style='width:80px'>" +
             "<a class='k-button k-button-icontext k-grid-delete'" +
         "<span class='k-icon k-delete'></span>Eliminar</a>" +
         "</td>" +
         "</tr>"
    )
    .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .PageSize(10)
        .ServerOperation(false)
        .Model(model =>
        {
            model.Id(p => p.Puim_clave);
        })
        .Read(read => read.Action("RowTemplate_Read", "Gestion"))
        .Destroy(destroy => destroy.Action("Editing_Destroy_Img", "Gestion"))

    )
    .Scrollable()
                )

And this is the controller action:

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Editing_Destroy_Img([DataSourceRequest] DataSourceRequest request, [Bind(Prefix = "models")]IEnumerable<TelerikMvcApp4.Models.PublicacionImagenModel> expedientes)
        {
            string sqlDelete = "delete from gmc_publicacion_imagen where puim_clave = :deletePub";

            HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);

            OracleConnection con = new OracleConnection(authTicket.UserData.ToString());
            OracleCommand cmd = new OracleCommand(sqlDelete, con);
            cmd.Parameters.Add(new OracleParameter("deletePub", OracleDbType.NVarchar2));

            try
            {
                con.Open();
                Permisos.OtorgarPermisos(con);
                //if (expedientes != null && ModelState.IsValid)
                //{
                foreach (var exp in expedientes)
                {
                    cmd.Parameters["deletePub"].Value = exp.Puim_clave;
                    cmd.ExecuteNonQuery();

                }
                //}
            }
            catch (Exception ex)
            {
                Session["excepcionGestion"] = ex;
            }
            finally
            {
                con.Close();
                con.Dispose();
                cmd.Dispose();
            }

            return Json(expedientes.ToDataSourceResult(request, ModelState));
        }

 

I'll wait for your answers. Thanks

2 Answers, 1 is accepted

Sort by
0
Juan
Top achievements
Rank 1
answered on 21 Oct 2016, 12:23 PM

Sorry, this is the controller action that i wanted to put:

public ActionResult RowTemplate_Read([DataSourceRequest]DataSourceRequest request)
        {
            string sqlString = "select * from gmc_publicacion_imagen";
            var listImagenesPub = new Models.ListIamgenesPub();

            HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
            FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value);

            OracleConnection con = new OracleConnection(authTicket.UserData.ToString());
            OracleCommand cmd = new OracleCommand(sqlString, con);

            try
            {
                con.Open();
                Permisos.OtorgarPermisos(con);
                using (OracleDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        
                        listImagenesPub.Add(new PublicacionImagenModel(
                            int.Parse(dr["PUIM_CLAVE"].ToString()),
                            int.Parse(dr["PUIM_CLAVE_PUB"].ToString()),
                            dr["PUIM_IMAGEN"] != DBNull.Value ? (byte[])(dr["PUIM_IMAGEN"]) : null
                            ));
                    }
                }
            }
            catch (Exception ex)
            {
                Session["ex"] = ex;
            }
            finally
            {
                con.Close();
                con.Dispose();
                cmd.Dispose();
            }

            return Json(listImagenesPub.ToDataSourceResult(request));
        }

0
Konstantin Dikov
Telerik team
answered on 24 Oct 2016, 12:38 PM
Hello Juan,

You need to use different content type for PNG, JPG and for GIF. You can find some information on this matter in the following forum thread:
In your current template you are using the png content type, which is why you are able to open only PNG files.

Hope this helps.


Regards,
Konstantin Dikov
Telerik by Progress
Check out the new UI for ASP.NET Core, the most complete UI suite for ASP.NET Core development on the market, with 60+ tried-and-tested widgets, based on Kendo UI.
Tags
Grid
Asked by
Juan
Top achievements
Rank 1
Answers by
Juan
Top achievements
Rank 1
Konstantin Dikov
Telerik team
Share this question
or