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

3 posts, 0 answers
  1. Juan
    Juan avatar
    22 posts
    Member since:
    Oct 2016

    Posted 21 Oct Link to this post

    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. Juan
    Juan avatar
    22 posts
    Member since:
    Oct 2016

    Posted 21 Oct in reply to Juan Link to this post

    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));
            }

  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 24 Oct Link to this post

    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.
Back to Top