File Uploading Immediately Triggers a Separate İnsert Operation With NULL Values Inserted.

File Uploading Immediately Triggers a Separate İnsert Operation With NULL Values Inserted.

naktunaktu Posts: 6Questions: 4Answers: 0

I am trying the file upload example. i have a row. i am trying to upload a file. 1 file for 1 row.

TABLE : rowID | fileName | sysPath | fileSize | tag1 | tag2 .....

i use create button. after (or before) filling the fields, i drag the file it uploads after the upload create form looks like i didn't upload (but it did). Table entry looks like this.

CREATE FORM : file | "asd" | "bla"

DATA BASE ENTRİES :
asd.pdf | /httpdocs/etc| 1234 | NULL | NULL
NULL | NULL | NULL | asd | "bla"

it uploads the file but db has 2 separate entry. I copied examples at documentation exactly except i am using same table for files . I do not know what i am doing wrong.

Editor::inst( $db, 'auc_makale', 'makaleid' )
    ->fields(
        Field::inst( 'makaleid' ),
        Field::inst( 'fileName' )->upload( Upload::inst(  $_SERVER['DOCUMENT_ROOT'].'/scripts/upfiles/__NAME__.__ID__.__EXTN__'  )->db( 'auc_makale', 'makaleid', array(
                'fileName' => Upload::DB_FILE_NAME,
                'fileSize' => Upload::DB_FILE_SIZE,
                'filePath' => Upload::DB_SYSTEM_PATH
            ) )
        )
        ->setFormatter( 'Format::nullEmpty' ),
        Field::inst( 'tag1' ),
        Field::inst( 'tag2' ),

...

    )
    ->process( $_POST )
    ->json();

Answers

  • naktunaktu Posts: 6Questions: 4Answers: 0

    Forgot to add.
    If i keep dragging new files to the Create form. All the files are getting uploaded and Database entries shows these file uploads. Is there a some kind of cache option which stores last file and waits for post commit ?

    Before DataTables, i usually stored files in DBcells, bloated and locked up by Base64 encoding. Impossible to pre- process or access metadata.

    I hope i missed something because that render function freaks me out.

  • allanallan Posts: 63,514Questions: 1Answers: 10,472 Site admin

    The examples use a separate table for the file upload meta information (simply called "files"). The file upload in Editor is indeed async, so it need to be able to write to the database at that point - hence the need for a second table.

    Since you refer to auc_makale in both the main Editor instance and the file upload, yes, there would be two entries, which obviously is not what you want. The way to fix that is to use a separate files table.

    Allan

This discussion has been closed.