Editor : upload-many and extra field

Editor : upload-many and extra field

Triskell2k1Triskell2k1 Posts: 4Questions: 1Answers: 0

I follow example about upload-many.
So the upload of files work properly, but now I want to add an extra field "comment" on table 'files' (ie. for all files I want to be able to specify a specific comment).

On server (Node in my case) & database (SQL): adding field --> OK

On client I don't know how I can add fields and that it will be "associated" with current file. I expect something like :

{
name: "files[].comment",
type: "textarea",
}

Is there a solution (without adding an intermediate table with the comment that join on one side user and other one file.

Answers

  • Triskell2k1Triskell2k1 Posts: 4Questions: 1Answers: 0
    edited May 2020

    Some precision on server, I can add field but with "static " value

    Upload(__dirname + '/edition/photos/{id}.{extn}')
      .db('photos', 'id', {
        filename: Upload.Db.FileName,
        filesize: Upload.Db.FileSize,
        web_path: 'photos/{id}.{extn}',
         system_path: Upload.Db.SystemPath,
         comment : '42' 
      }
    )
    

    instead of 42, I could get data in requete.body but they are not specific for the files but for the parent, and what I'm looking for is set specific element in client side and get it on server side (for example avaibility to add custom field to Upload.Db)

  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin

    I'm sorry to say that what you are looking for is not currently possible with Editor. In part this is due to to its async upload action - consider for example entering the comment after uploading the file - the file is already in the database.

    You could use preUpload to add the value from a field (to then replace your 42), but that wouldn't solve the issue I mention above. The only way to do that would be to have a table specifically for the uploaded files, allowing direct editing of that, and then link to that table from your other one.

    Sorry I don't have better news atm.

    Allan

  • Triskell2k1Triskell2k1 Posts: 4Questions: 1Answers: 0

    Thank's, so I will use 2 different tables
    The first one for upload, which allow to add/delete element
    and the 2nd one, the "real table" with other fields for editing.
    Basic information (filename) will be inserted in 2nd table "automatically" during upload with a custom action like this.
    On my datatable I will add the 2nd table in one cell to display and edit data
    So for adding data it will be done in 2 step first upload (by editing row in main datatable), 2nd one complete field in "child" datatable.

    Do you think it's a good solution (even if i'm not sure I'm clear) ?

                            .action(
                                async function (file, id) {
                                    fs.rename(file.file, __dirname + `/edition/documents/${id}.${file.extn}`, function () { });
    
                                    await dbMySQL('documents').insert({
                                        id: id,
                                        ext: file.extn,
                                    });
                                    return id;
                                }
                            )
    
  • allanallan Posts: 63,195Questions: 1Answers: 10,412 Site admin
    edited May 2020

    Yes, that sounds good to me (assuming I've understood correctly :) ),

    Allan

This discussion has been closed.