Custom upload actions send data to Front end

Custom upload actions send data to Front end

ClarenceClarence Posts: 19Questions: 7Answers: 0
  new Field('image').validator(Validate.notEmpty()).upload(
        new Upload(async (fileInfo, id) => {
          const file = await readFile(fileInfo.file);
          await rename(fileInfo.file, `${__dirname}/../public/uploads/{id}.{fileInfo.extn}`);
          Upload.Db.file = `data:${fileInfo.mimetype};base64,${file.toString('base64')}`;     <----- May I use this to set Upload.Db
          Upload.Db.web_path = '/uploads/'+ id + '.' + fileInfo.extn;     <----- May I use this to set Upload.Db
          Upload.Db.system_path = `${__dirname}` + '/../public/uploads/' + id + '.' + fileInfo.extn;     <----- May I use this to set Upload.Db
          return id;
        })
          .db('files', 'id', {
            filename: Upload.Db.FileName,
            filesize: Upload.Db.FileSize,
            web_path: Upload.Db.web_path,      <----- This I want to send to front end
            system_path: Upload.Db.system_path,      <----- This I want to send to front end
            file: Upload.Db.file      <----- This I want to send to front end
          })

This question has an accepted answers - jump to answer

Answers

  • ClarenceClarence Posts: 19Questions: 7Answers: 0

    I want to use like this

    return '<img src="'+editor.file( 'files', file_id ).file+'"/>';
    
  • allanallan Posts: 63,457Questions: 1Answers: 10,466 Site admin

    If you have a look at the Ajax response from the server when loading the table, it should already have those three parameters. Can you give me a link to the page so I can take a look please?

    Thanks,
    Allan

  • ClarenceClarence Posts: 19Questions: 7Answers: 0

    Thank I use other ways to solve the problem

  • ClarenceClarence Posts: 19Questions: 7Answers: 0

    I think I can express my problem more clearly.
    My problem is that I want to save the image as "base64 image".

    Upload.Db.file = `data:${fileInfo.mimetype};base64,${file.toString('base64')}`;
    

    Then the front end can read this photo directly.
    But I use

    Upload.Db.file
    

    It can't be use.

  • CTC SoftwareCTC Software Posts: 1Questions: 0Answers: 1
    Answer ✓

    This is what I use, you may find it similar in your DB structure

                { data: "colorimage.ImageFilePNGBytes" ,
                                 render: function ( data, type, row ) {
                                     if (data.length < 25) { 
                                     var  thumbnail = '<img title="No Image Specified" class="img-responsive" style="width:64px;" src="/img/default.png" />';   
                                     } else { 
                                      thumbnail = '<img title="'+row.color.Name+'" class="img-responsive"  style="width:64px;" src="data:image/png;base64,'+ data +'" />';
                                     }
                                     return thumbnail;
                                } 
                            },
    

    the render calls the data from the JSON returned which contains the BLOB field

    I am still looking, however, for a solution to my problem of using the Upload with BLOB fields.
    Also, you may note that upload cannot be used with BLOB field on the same table

This discussion has been closed.