File uploaded to a field that does not have upload options configured

File uploaded to a field that does not have upload options configured

azonekz@gmail.comazonekz@gmail.com Posts: 26Questions: 9Answers: 1
edited January 2 in DataTables

Hi, when I'm trying to upload a file I have an error: "File uploaded to a field that does not have upload options configured". Help me please

Controller:

public ActionResult JTovar()
        {
            var request = System.Web.HttpContext.Current.Request;
            var settings = Properties.Settings.Default;
            using (var db = new DataTables.Database(settings.Dbtype, settings.DbConnection))
            {
                var response = new Editor(db, "Tovar", "id")
                    .Model<ModelTovar>()
                    .Field(new Field("Tovar.id"))   
                                     
                    .MJoin(new MJoin("image")
                            .Link("Tovar.id", "interImage.idTovar")
                            .Link("image.id", "interImage.idImage")
                    .Model<MjoinImageTovar>()
                    .Field(
                       new Field("Tovar.Links")                                     
                           .Upload(
                           new Upload(request.PhysicalApplicationPath + @"uploads\__ID____EXTN__")
                           .Db("image", "id", new Dictionary<string, object>
                           {
                              {"fileName", Upload.DbType.FileName},
                              {"fileSize", Upload.DbType.FileSize},
                              {"webPath", Upload.DbType.WebPath},
                              {"systemPath", Upload.DbType.SystemPath}
                           })
                           .Validator(Validation.FileSize(50000000, "Max file size is 500000K."))
                           .Validator(Validation.FileExtensions(new[] { "jpg", "png", "gif","html","htm" }, "Please upload an image or html file."))
                                  )
                          .SetFormatter(Format.NullEmpty())
                            )                  
                          )
                    .Process(request)
                    .Data();
                return Json(response, JsonRequestBehavior.AllowGet);
            }
        }
{
                label: "Links:",
                name: "Tovar.Links",
                type: "uploadMany",
                display: function (id) {
                    return '<img src="' + editor.file('image', id).webPath + '"/>';
                },
                noImageText:'No image'
            }
------------------------------------------------------------------------------------------------------
{
             data: "Tovar.Links",
             render: function (data)
             {
                 console.log(data);
                 return data?             
                      data.length + ' files(s)' :
                       'No file';
             },
             title: "Image"
         }
--------------------------------------------------------------------------------------------------------

Models:

 public class MjoinImageTovar
    {
        public class interImage
        {
            public int id { get; set; }
            public int idTovar { get; set; }
            public int idImage { get; set; }

        }
        public class image
        {
            public int id { get; set; }
            public string fileName { get; set; }
            public int fileSize { get; set; }
            public string webPath { get; set; }
            public string systemPath { get; set; }
        }
    }
public class ModelTovar
    {
        public class Tovar
        {
            public int id { get; set; }         
            public string Links { get; set; }
           
        }

Edited by Allan Formatting using markdown.

Answers

  • allanallan Posts: 48,657Questions: 1Answers: 7,068 Site admin

    Can you show me your db schema please? I'm a little confused by the use of uploadMany for a field that is not in an mJoin.

    Allan

  • azonekz@gmail.comazonekz@gmail.com Posts: 26Questions: 9Answers: 1

  • azonekz@gmail.comazonekz@gmail.com Posts: 26Questions: 9Answers: 1

    Help me please to find out what is wrong with my code.

  • allanallan Posts: 48,657Questions: 1Answers: 7,068 Site admin

    Thanks - I believe the issue is that the upload should actually be on the Mjoin. For example:

                        .MJoin(new MJoin("files")
                            .Link("users.id", "users_files.user_id")
                            .Link("files.id", "users_files.file_id")
                            .Field(
                                new Field("id")
                                    .Upload(new Upload(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", "__ID____EXTN__"))
                                        .Db("files", "id", new Dictionary<string, object>
                                        {
                                            {"web_path", Path.DirectorySeparatorChar+Path.Combine("uploads", "__ID____EXTN__")},
                                            {"system_path", Upload.DbType.SystemPath},
                                            {"filename", Upload.DbType.FileName},
                                            {"filesize", Upload.DbType.FileSize}
                                        })
                                        .Validator(Validation.FileSize(500000, "Max file size is 500K."))
                                        .Validator(Validation.FileExtensions(new[] { "jpg", "png", "gif" }, "Please upload an image."))
                                    )
                            )
                        )
    

    Is the C# version of the PHP upload many example.

    For the upload many field on the client-side you want to use:

    name: "image[].id",
    

    since image is the array of items for the files.

    Allan

  • azonekz@gmail.comazonekz@gmail.com Posts: 26Questions: 9Answers: 1

    Thanks for response Allan.
    Upload was already on the Mjoin. I changed code like you advised:

    {
    label: "Links:",
    name:"image[].id",
    type: "uploadMany",
    display: function (id) {
    return '<img src="' + editor.file('image', id).webPath + '"/>';

    },
    noImageText:'No image'
    }

    Controller:

    .MJoin(new MJoin("image")
    .Link("Tovar.id", "interImage.idTovar")
    .Link("image.id", "interImage.idImage")
    .Model<MjoinImageTovar>()
    .Field(
    new Field("id")

    .Upload(
    new Upload(request.PhysicalApplicationPath + @uploads__ID____EXTN__)
    .Db("image", "id", new Dictionary<string, object>
    {
    {"fileName", Upload.DbType.FileName},
    {"fileSize", Upload.DbType.FileSize},
    {"webPath", Upload.DbType.WebPath},
    {"systemPath", Upload.DbType.SystemPath}
    })
    .Validator(Validation.FileSize(50000000, "Max file size is 500000K."))
    .Validator(Validation.FileExtensions(new[] { "jpg", "png", "gif","html","htm" }, "Please upload an image or html file."))
    )
    .SetFormatter(Format.NullEmpty())
    )
    )

    Now it's working for uploading many files, but when I'm trying to update a row with already uploaded files I have an error: dataTables.editor.min.js:12 Uncaught Unknown file table name: image
    I don't understand how to fix it. Thanks.

Sign In or Register to comment.