Upload files to a table

Upload files to a table

shuminliushuminliu Posts: 14Questions: 6Answers: 0
edited August 8 in Editor

The upload example uses Users.Image as the anchor field for Upload (Users.Image is an FK to Files table). I'm trying to manage a table MyFiles directly: MyFiles has columns Id, FileName, ContentType, FileSize, BinaryContent. I'd like to have a datatable showing the list of files and an Editor popup that just shows an Upload field where I can choose a file and then Create/Update. I'm wondering if this is possible. Thanks!

Answers

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    Hmmm - good question! I've never tried it before, but I don't see why not. Your "create" view would be replaced by an Editor form with just an upload field, and you could close on uploadComplete. The "edit" field would list the fields with the file properties (size, etc - not sure you'd what them to be end user editable though).

    Allan

  • shuminliushuminliu Posts: 14Questions: 6Answers: 0

    Hi, Allan,

    I was hoping this scenario would be feasible:

    imagine Users.Image is not an integer but a text/varchar(max) field that hosts base64Encoded string of any file (we could add a Users.Image_File_Type to help record the content type), and Editor could directly upload a file's content to the Image field, given

    $(document).ready(function() {
    editor = new $.fn.dataTable.Editor( {
    ajax: "/api/upload",
    table: "#example",
    fields: [ {
    label: "First name:",
    name: "first_name"
    },
    {
    label: "File Type:",
    name: "image_file_type" //could be a Select with options pdf/jpeg/gif/word
    },
    ............
    {
    label: "Image:",
    name: "image",
    type: "upload.Base64", // or upload.Bytes if Image is a blob
    display: function ( ) {
    return "<a href=...>Click here to view file</a>";
    },

    then on the server side (api/upload) we could bypass the step of saving files to a folder and just treat the Image field as a regular field (without .Upload().Db()).

    I guess I'm getting lazier and lazier after using your DataTables since it saves so much time and effort :) I know what I'm hoping might not be realistic - just my humble two cents.

    Best Regards.

  • allanallan Posts: 63,676Questions: 1Answers: 10,497 Site admin

    So at the moment, no, that is not something that Editor supports out of the box, but it would be possible to do with a custom field type. A field that accepts a file, and would use Javascript to get and store the base64 value of the file, rather than immediately submitting it to the server (i.e. treating the base64 representation as a string value, just as text treats a string as a value.

    It's not a bad idea this, and I will have a look at creating such a field type for 2.4. It's in my issue tracker now!

    Regards,
    Allan

Sign In or Register to comment.