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: 32Questions: 9Answers: 1
edited January 2019 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: 63,368Questions: 1Answers: 10,449 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: 32Questions: 9Answers: 1

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

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

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 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: 32Questions: 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.

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

    Hi,
    I am suffering from another problem.
    I can't get information about uploaded file.
    if editor.file('image') is called, then it returns error message "Unknown file table name: image". If editor.files() is called, then it returns empty object -> { }

    Can you help me, please?
    I use editor 1.8.1

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    Can you show me the JSON being returned by the server when the table is first loaded? Even better would be a link to the page showing the issue so I can debug it.

    Thanks,
    Allan

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

    Yes, sure, the link is: http://tfl.igyrus.com/Tables/Tovar
    Please, create a new entity with (downloaded image), refresh the page and try to edit this entity.
    Thanks in advance.

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    Thanks for the link. I'm getting an error though:

    http://tfl.igyrus.com/Scripts/dataTables.editor.min.js 404 (Not found)

    That's interrupting the Javascript and nothing else is happening (as the main code us attempting to do new $.fn.dataTable.Editor(...) which is failing).

    Allan

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

    Thanks for reponse. Try it now again, please.

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

    Hi Allan.
    Can you check it again, please?

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    Thank you. When the page is reloaded I see files: {} in the JTovar JSON response, so Editor is correct on the client-side in reporting the error it is. That object should contain information about the file(s). See this section of the docs.

    You can also see the expected behaviour by experimenting with the demo upload page.

    Allan

  • allanallan Posts: 63,368Questions: 1Answers: 10,449 Site admin

    Sorry - I'd forgotten you were using the .NET libraries for Editor. Can you show me the full Controller please?

    Thanks,
    Allan

  • azonekz@gmail.comazonekz@gmail.com Posts: 32Questions: 9Answers: 1
    edited January 2019

    Controller:

        [AcceptVerbs(HttpVerbs.Get | HttpVerbs.Post)]
                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")
                            .Validator(Validation.NotEmpty())
                            )
                        .Field(new Field("Tovar.Name")
                            .Validator(Validation.NotEmpty())
                            )
                        .Field(new Field("Tovar.Quantity")
                            .Validator(Validation.NotEmpty())
                            )
                        .Field(new Field("Tovar.Col")
                        .Options(new Options()
                        .Table("Columns")
                        .Value("Number")
                        .Label("Number")
                        )
                         .Validator(DataTables.Validation.DbValues(new ValidationOpts { Empty = false }))
                        )
                        .Field(new Field("Tovar.Range")
    
                            )
                        .Field(new Field("Tovar.Box")
                        .Options(new Options()
                        .Table("Box")
                        .Value("Number")
                        .Label("Number")
                         )
                         .Validator(DataTables.Validation.DbValues(new ValidationOpts { Empty = false }))
                        )
                        .Field(new Field("Tovar.Price")
    
                            )
                        .Field(new Field("Tovar.ShippingPrice")
    
                            )
    
                        .Field(new Field("Tovar.DateDeCreation")
    
                           .GetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601))
                          .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601))
                            )
                        .Field(new Field("Tovar.DateOfSale")
    
                         .GetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601))
                          .SetFormatter(Format.DateFormatToSql(Format.DATE_ISO_8601))
                            )
    
                        .Field(new Field("Tovar.Category")
                        .Options(new Options()
                        .Table("Category")
                        .Value("Name")
                        .Label("Name")
                         )
    
                        )
                         .Field(new Field("Tovar.Attention")
                        .Options(new Options()
                        .Table("AttentionMessage")
                        .Value("Name")
                        .Label("Name")
                         )
    
                        )
    
                        .Field(new Field("Tovar.StatusEbay")
                        .Options(new Options()
                        .Table("Status")
                        .Value("Name")
                        .Label("Name")
                         )                  
                        )
                        .Field(new Field("Tovar.ProfitEbay")
                            )
    
                        .Field(new Field("Tovar.StatusAmazon")
                        .Options(new Options()
                        .Table("Status")
                        .Value("Name")
                        .Label("Name")
                         )
                        )
                        .Field(new Field("Tovar.ProfitAmazon")
                            )
    
                        .Field(new Field("Tovar.StatusKijiji")
                        .Options(new Options()
                        .Table("Status")
                        .Value("Name")
                        .Label("Name")
                         )
                        )
                        .Field(new Field("Tovar.ProfitKijiji")
                            )
    
                        .Field(new Field("Tovar.FinalProfit")
                            )
                            .Field(new Field("Tovar.Width")
                            )
                            .Field(new Field("Tovar.Height")
                            )
                            .Field(new Field("Tovar.Depth")
                            )
                            .Field(new Field("Tovar.Weight")
                            )
                            .Field(new Field("Tovar.LocalLink")
                            )
                            .Field(new Field("Tovar.EbayLink")
                            )
                            .Field(new Field("Tovar.AmazonLink")
                            )
                            .Field(new Field("Tovar.KijijiLink")
                            )
                        .LeftJoin("Columns", "Columns.Number", "=", "Tovar.Col")
                        .LeftJoin("Box", "Box.Number", "=", "Tovar.Box")
                        .LeftJoin("Category", "Category.Name", "=", "Tovar.Category")
                        .LeftJoin("AttentionMessage", "AttentionMessage.Name", "=", "Tovar.Attention")
                        .LeftJoin("Status", "Status.Name", "=", "Tovar.StatusEbay")
    
                        .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())
                                )
    
    
                              )
                              .Field(new Field("Tovar.Operator")
                              )
                               .Field(new Field("Tovar.sold")
                              )
    
    
                        .Process(request)
                        .Data();
                    return Json(response, JsonRequestBehavior.AllowGet);
    
    
                }
            }
    
  • azonekz@gmail.comazonekz@gmail.com Posts: 32Questions: 9Answers: 1

    Hi Allan,
    can you check it, please?

This discussion has been closed.