F
F
futurist082020-01-15 10:38:58
progress bar
futurist08, 2020-01-15 10:38:58

Laravel vue axios how to make progress bar?

good afternoon dear experts. tell me how to make laravel vue asios script progress bar.
there is a back controller

public function rasFileRecord($dir, $file, Request $request)
    {
        $all=count($zap);
        foreach ($zap as $z) {
            $rasZap = $this->rasZap->createOrUpdateZap($z, $rasFileDb->id);
            $this->rasSl->createOrUpdateSL($z, $rasZap->id);
            $n++;
            Session::pull('progress', $n);
            session('progress', $n);
            $_SESSION['progress']=$n;
                       response()->json(['message'=>'test']);
        }
    }

there is a vue procedure
const CancelToken = axios.CancelToken;
      this.source = CancelToken.source();
      this.loading = true;
      let dir = this.$route.params.dir;
       axios
        .get(`/api/v1/ras-file-record/${dir}/${nameFile}`, {
          cancelToken: this.source.token,
          onDownloadProgress: progressEvent => {
            let contentLength = event.srcElement.getResponseHeader(
              "content-length"
            );
            let percentCompleted = Math.round(
              (progressEvent.loaded * 100) / progressEvent.total
            );
            /*let data = this.$session.get("progress");
            console.log(data);*/
            //console.log(progressEvent);
            //console.log(percentCompleted);
          }
        })
        .then(resp => {
          this.loading = false;
          console.log(resp);
        })
        .catch(err => {
          console.log(err);
        });

the main question is how to return intermediate processing results from laravel and how to pick them up in an axios request.
I tried to pick up standard sessions at intervals (js does not see them). headers also does not work, since axios receives them with the response. Maybe there is some other option. Thank you.
Unfortunately, the processing process does not depend on the file upload and does not transfer to the front, dowload, or upload. how to be in that case?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2020-01-15
@Nc_Soft

Yes, there is another option
https://www.nginx.com/resources/wiki/modules/uploa...
ps if it's not about uploading a file, then you need to make an endpoint that gives progress and hammer there at intervals

F
futurist08, 2020-01-21
@futurist08

Unfortunately, the processing process does not depend on the file upload and does not transfer to the front, dowload, or upload. how to be in that case?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question