Unknown file id 5 in table files with file upload

Unknown file id 5 in table files with file upload

klinglerklingler Posts: 90Questions: 42Answers: 2

Good day....

Currently working on the file upload section in our tool...

I select an existing row and edit it...then choose a file and upload it for processing...

So what "id" value in the "upload" array is the uploader expecting?

When uploading a file a reference will be entered in pgsql returning the unique fileid
which I use as the "id" value returning to file uploader...

But I see in the console:

uncaught exception: Unknown file id 5 in table files

When I return fixed 0 as id then it is fine...but won't work for multiple files....

thanks in advance
richard

This question has an accepted answers - jump to answer

Answers

  • klinglerklingler Posts: 90Questions: 42Answers: 2

    This is the JSON I return after file has been uploaded successfully...

    {"data":[],"files":{"files":{"1":{"id":"7","filename":"IMG_1419.jpeg","filesize":187277,"icon":"<i class=\"mdi mdi-file-image\"><\/i>.","system_path":"\/var\/www\/order\/html_public\/uploads\/IMG_1419.jpeg"}}},"upload":{"id":"7"}}

    What I am missing...it doesn't send any reference to the DT_RowId for the uploaded file...only:

    Array
    (
    [action] => upload
    [uploadField] => files[].id
    )

  • klinglerklingler Posts: 90Questions: 42Answers: 2

    Okay...seems I misinterpreted the JSON returned from the example wrong...

    So upload is fine with no error messages....and displays nicely then in the dialog:

    But how do I know in the file upload handler to which row the files are belonging to?

  • klinglerklingler Posts: 90Questions: 42Answers: 2

    Hmm..this seems to do the trick for the upload ajax:

                ajaxData: function(d) {
                    d.append('id', editor.ids());
                },
    
  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin

    Going back to the JSON return - the keys for the inner files object should be the id of the entry in the database - i.e.:

    {
        "data": [],
        "files": {
            "files": {
                "7": {
                    "id": "7",
                    "filename": "IMG_1419.jpeg",
                    "filesize": 187277,
                    "icon": "<i class=\"mdi mdi-file-image\"><\/i>.",
                    "system_path": "\/var\/www\/order\/html_public\/uploads\/IMG_1419.jpeg"
                }
            }
        },
        "upload": {
            "id": "7"
        }
    }
    

    It looks at the object's keys, not the values inside it.

    Allan

  • allanallan Posts: 61,650Questions: 1Answers: 10,094 Site admin
    Answer ✓

    But how do I know in the file upload handler to which row the files are belonging to?

    You don't. You've got a workaround for edit - but what about create when there is no id yet? The file upload doesn't need to know the host row id, it's the other way around - the host row needs to know the id for the file.

    Allan

This discussion has been closed.