nabilunfarhanun's avatar

How to show file upload status in laravel?

I have a controller that takes a lot of data by file and inserts it into the database. How can I show the user some status about how much code is run.

For example, I want to show statuses like, "file upload was done", "data is being validated", "data is inserted" etc. My initial approach was to use the session.

I inserted something like the following in appropriate places on controllers.

..
..code for file upload
..
session()->put('_order_upload_status','file upload done');

..
..code for validation
..
session()->put('_order_upload_status','data is being validated');

Then on the front end, I ran a bit of js code to get the status periodically.

function intervalAction()
  {
    var intervalID = window.setInterval(getStatus, 500);
  }
function getStatus()
  {
    var request = new XMLHttpRequest();
    var url = '{{ route('order.upload.getStatus') }}';
    request.open('GET',url,true);

    request.onload = function(){
      document.getElementById('percentageModalTextBox').innerHTML = this.response
    };
    request.send();
  }

The url {{ route('order.upload.getStatus') }} does nothing more than to get the session data.

However, this approach is not working. I can get the correct session only after the file upload controller runs completely. So I am getting nothing for a long time and only the last status after everything is over.

How can I show the status update to the user?

0 likes
0 replies

Please or to participate in this conversation.