请求的资源Laravel 5.7上没有'Access-Control-Allow-Origin'标头

时间:2018-12-06 09:23:04

标签: laravel api vue.js cors axios

我想从另一个URL下载视频文件,但不适用于我的laravel项目。而我收到此错误

Access to XMLHttpRequest at 'http://localhost/blog/public/uploads/video/1543647797BirdNoSound.mp4' from origin 'http://103.54.150.38:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

我已经在我的laravel项目中安装了https://packagist.org/packages/spatie/laravel-cors这个包

这是我的vue js代码

axios({
          url: 'http://103.54.150.38/blog/public/uploads/video/1543647797BirdNoSound.mp4',
          method: 'GET',
          responseType: 'blob', // important
        }).then((response) => {
          FileSaver.saveAs(new Blob([response.data]));
          const url = window.URL.createObjectURL(new Blob([response.data]));
          const link = document.createElement('a');
          link.href = url;
          link.setAttribute('download', 'video_file.mp4'); //or any other extension
          document.body.appendChild(link);
          link.click();
        });

0 个答案:

没有答案