Editor and node.js - Upload not work in case of two images and only second images is uploaded

Editor and node.js - Upload not work in case of two images and only second images is uploaded

CapamaniaCapamania Posts: 229Questions: 79Answers: 5
edited December 2020 in Editor

Editor and node.js. I have a setup where two files can be uploaded for a record. If I only upload the second image and reload the page I'm getting an error in the frontend:

Uncaught Unknown file table name: files_img

My server script looks like this where I use two file tables::

  new Field( 'accounts.file_avatar' )
    .upload(
      new Upload( __dirname + '/../public/uploads/avatar/{id}.{extn}' )
        .db('files_avatar', 'id', {
            filename: Upload.Db.FileName,
            filesize: Upload.Db.FileSize,
            web_path: config.URL_DOMAIN+'/uploads/avatar/{id}.{extn}',
            system_path: Upload.Db.SystemPath
        })
        ...
    ),
  new Field( 'accounts.file_img' )
    .upload(
      new Upload( __dirname + '/../public/uploads/img/{id}.{extn}' )
        .db('files_img', 'id', {
          filename: Upload.Db.FileName,
          filesize: Upload.Db.FileSize,
          web_path: config.URL_DOMAIN+'/uploads/img/{id}.{extn}',
          system_path: Upload.Db.SystemPath
        })
        ...
    ),

Scenario 1 (Works):

It works fine if I upload both images. In the response I get:

files   Object { files_avatar: {…}, files_img: {…} }
    files_avatar    Object { 1: {…} }
        1   Object { id: 1, filename: "logo.png", filesize: "3695", … }
            id  1
            filename    "logo.png"
            filesize    "3695"
            web_path    "http://127.0.0.1:4000/uploads/avatar/1.png"
            system_path "/home/test/controllers/../public/uploads/avatar/1.png"
    files_img   Object { 1: {…} }
        1   Object { id: 1, filename: "board.jpg", filesize: "33282", … }
            id  1
            filename    "board.jpg"
            filesize    "33282"
            web_path    "http://127.0.0.1:4000/uploads/img/1.jpg"
            system_path "/home/test/controllers/../public/uploads/img/1.jpg"

Scenario 2 (Works):

If I only save the first image 'files_avatar' it also works. Response result:

files   Object { files_avatar: {…}, files_img: {} }
    files_avatar    Object { 1: {…} }
        1   Object { id: 1, filename: "logo.png", filesize: "3695", … }
            id  1
            filename    "logo.png"
            filesize    "3695"
            web_path    "http://127.0.0.1:4000/uploads/avatar/1.png"
            system_path "/home/test/controllers/../public/uploads/avatar/1.png"
    files_img   Object { }

Scenario 3 (Does not work):

But if I only want to save the second image 'files_img' and leave the avatar empty ... the information is stored in the db and the file is uploaded ... BUT the files object in the response is empty:

files   Object { }      

I still can call the editor if I refresh the table. But if I reload the page I can't even call the editor and I'm getting this error message in the frontend as well:

    Uncaught Unknown file table name: files_img

How can I prevent this and only upload the later image? It seems like the files join was deleted because of the first empty file but then ignores that there is a second.

That's how my frontend script looks like:

{
label: "Avatar:",
name: "accounts.file_avatar",
className: 'block full dt-avatar',
type: "upload",
ajaxData: function ( d ) {
    // ...
},
display: function ( file_id ) {
    if(file_id){
        return '<img src="'+editor_accounts.file( 'files_avatar', file_id ).web_path+'"/>';
    } else {
        return null;
    }
},
clearText: "Clear",
noImageText: "No file selected"
}, {
label: "Image:",
name: "accounts.file_img",
className: 'block full dt-img',
type: "upload",
ajaxData: function ( d ) {
    // ...
},
display: function ( file_id ) {
    if(file_id){
        return '<img src="'+editor_accounts.file( 'files_img', file_id ).web_path+'"/>';
    } else {
        return null;
    }
},
clearText: "Clear",
noImageText: "No file selected"
}, 

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    What version of the server-side libraries are you using please? I recall a bug about this, but it was a while back...

    Thanks,
    Allan

  • CapamaniaCapamania Posts: 229Questions: 79Answers: 5

    Hi Allan, I'm using "datatables.net-editor-server": "^1.9.2". Thanks for the support!

  • colincolin Posts: 15,112Questions: 1Answers: 2,583

    We're currently on 1.9.6, would it be possible to upgrade and see if that makes a difference, please?

    Colin

This discussion has been closed.