File Upload return an error

File Upload return an error

Andreas S.Andreas S. Posts: 208Questions: 74Answers: 4
edited October 2023 in Editor

I would like to upload a file using the editor. The file is also uploaded and is on the server, but the client always gives me the error message: "A server error occurred while uploading the file"
I checked what the server was sending back and according to the documentation that would be correct. I'm currently at a loss as to where the error is.

js file:

var impLxf;

$(function () {
  var dtButtons = [];

  impLxf = new $.fn.dataTable.Editor({
    ajax: 'assets/php/fs-server-backend.php?rec=3',
    table: '#records_tbl',
    display: 'bootstrap',
    // template: '#iR',
    fields: [
      {
        label: 'Lenex 3.0 file',
        name: 'filename',
        type: 'upload',
        display: function (fileId) {
          console.log(fileId);
          return impLxf.file('files', fileId).filename;
        }
      }],
    dragDrop: false
  });

  dtButtons.push({
    extend: 'create',
    editor: impLxf,
    className: 'ml-5 text-green bold',
    text: '<i class="fa-regular fa-file-import"></i>',
    titleAttr: 'Import Records from lenex file',
    formButtons: [
      { text: 'Import', action: function () { this.submit(); }, className: 'btn-danger mr-5' },
      { text: 'Cancel', action: function () { this.close(); }, className: 'btn-primary' }
    ],
    formTitle: '<i class="fa-regular fa-file-import text-red bold"></i> <span class=text-red bold>Import Lenex 3.0 file</span>'
  });

  var table = $('#records_tbl').DataTable({
    ajax: {
      url: 'assets/php/fs-server-backend.php?rec=1&g=' + g + '&c=' + c + '&a=' + a,
      type: 'POST'
    },
    autoWidth: false,
    select: true,
    serverSide: true,
    processing: true,
    ordering: false,
    pagingType: 'numbers',
    pageLength: 22,
    dom: "<'row'<'col-sm-12 DT_Buttons_Style'B>>rt<'row'<'col-sm-6'><'col-sm-6'>>",
    columnDefs: [
      { targets: 0, visible: true, className: 'text-right', width: '8%' },
      { targets: 1, visible: true, className: 'text-left', width: '3%' },
      { targets: 2, visible: true, className: 'text-right', width: '3%' },
      { targets: 3, visible: true, className: 'text-left' },
      { targets: 4, visible: true, className: 'text-left' },
      { targets: 5, visible: true, className: 'text-center', width: '3%' },
      { targets: 6, visible: true, className: 'text-left' },
      { targets: 7, visible: true, className: 'text-right' },
      { targets: 8, visible: true, className: 'text-center' },
      { targets: 9, visible: true, className: 'text-right', width: '3%' },
      { targets: '_all', visible: false, searchable: false, orderable: false }
    ],
    columns: [
      {
        data: 'distance'
      }, {
        data: 'stroke'
      }, {
        data: 'swimTime', render: function (data) {
          return ('00:00.00' == data || 'NT' == data) ? '' : data;
        }
      }, {
        data: null, render: function (data) {
          return ('' == data.lastnameprefix || null == data.lastnameprefix) ? data.lastname : data.lastnameprefix + ' ' + data.lastname;
        }
      }, {
        data: 'firstname'
      }, {
        data: 'birthdate', render: function (data) {
          moment.locale('de-at');
          return ('0000-00-00' == data) ? '' : moment(data).format('YYYY');
        }
      }, {
        data: 'clubname'
      }, {
        data: 'meetcity'
      }, {
        data: null, render: function (data) {
          moment.locale('de-at');
          if (0 == data.confirm.length && 'NT' != data.swimTime) {
            return '<i class="fas fa-question txt-Crimson" title="wird geprüft!"></i>';
          } else if (0 == data.confirm.length && 'NT' == data.swimTime) {
            return '';
          } else {
            return '<i class="fas fa-check txt-Green" title="Confirmed: ' + moment(data.confirm).format('DD.MMMM.YYYY') + '"></i>';
          }
        }
      }, {
        data: 'recdate', render: function (data) {
          moment.locale('de-at');
          return ('0000-00-00' == data) ? '' : moment(data).format('DD.MM.YYYY');
        }
      }
    ],
    buttons: {
      dom: {
        container: {
          className: 'dt-buttons btn-group'
        }
      },
      buttons: dtButtons
    },
    initComplete: function (data) {
      $('#records_tbl').removeClass('d-none');
    }
  });

});

json response:

{
  "files": {
    "files": {
      "1": {
        "fileId": 1,
        "filename": "lcm-01-06-23.lxf"
      }
    }
  },
  "upload": {
    "fileId": 1
  }
}

Andreas

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin

    "A server error occurred while uploading the file"

    That means that non-valid JSON was returned. There must be something other than the above in the response from the server. Perhaps try clicking on the "raw" option (if your browser has one) for response view in the network inspector.

    If you can give me a link to the page I can take a look.

    Allan

  • Andreas S.Andreas S. Posts: 208Questions: 74Answers: 4

    I have send you over PM the access data for my problem.

    Andreas

Sign In or Register to comment.