CORS政策-Access-Control-Allow-Origin标头包含多个值

时间:2019-03-10 02:45:45

标签: cors cross-domain jquery-file-upload

当我尝试使用jquery文件上载blueimp https://github.com/blueimp/jQuery-File-Upload上载文件到远程服务器时出现此错误

从原点“ https://stream.example.com/media/add_media”到“ https://stage.example.com”的XMLHttpRequest的访问已被CORS策略阻止:对预检请求的响应未通过访问控制检查:“访问控制-Allow-Origin'标头包含多个值'*,*',但只允许一个。

本地主机

var sendData= true;  
        $('.media_file').fileupload({
          dataType: 'json',
          singleFileUploads:true,
          maxChunkSize: 500000,
          autoUpload:false,
          replaceFileInput:false,
          add: function (e, data) { 

              $(".upload-btn").on('click', function () {
                //on click of this button data submitted

                data.url = 'https://streaming.example.com/media/add_media';

                  data.submit();
              });
          },
          done: function (e, data) {
              //data submitted return filename and remove files input

              $('.media_file').remove();
              $.each(data.result.files, function (index, file) {
                  $("input[name='filename']").val(file.name);
              });

              $("#form1").submit();
          }
        });

远程服务器crossdomain.xml

<?xml version="1.0"?>   
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
    <site-control permitted-cross-domain-policies="all"/>
    <allow-access-from domain="*.example.com" secure="false"/>
    <allow-access-from domain="www.example.com" secure="false"/> 
    <allow-http-request-headers-from domain="*" headers="*" secure="false"/>
</cross-domain-policy>

add_media控制器(远程服务器)

class Media extends CI_Controller {

    function __construct() {
        parent::__construct();
        $arrmodel=array('media_model');
        $this->load->model($arrmodel);

    }

    function add_media() {

        $filename = explode(".",$_FILES['files']['name']);
        $extension = end($filename);
        array_pop($filename);
        $filename = implode(".",$filename);

        $_FILES['files']['name'] = uniqid().".".$extension;

        $options = array('upload_dir' => FCPATH.'streams/videos/' , 'upload_url' => FCPATH.'streams/videos/');


        $this->load->library("UploadHandler",$options);

        return $_FILES['files']['name'];

    }

}

0 个答案:

没有答案