JS解决OSS上传跨域问题

废话不多说直接上代码

 var xhr = new XMLHttpRequest();
 var action = "" //oss链接
    xhr.withCredentials = false;
          xhr.open("POST", action);
          xhr.onload = () => {
            console.log(xhr.response); //输出结果
            if (xhr.response.indexOf("<Key>")) {
              let id = xhr.response.split("<Key>")[1].split("</Key>")[0];
              if (id == ossKey) {
                this.form.taskId = taskId;
                this.form.fileName = fileName;
              }
            }
          };
          //form参数
          var formData = new FormData();
          formData.append("ossid", ossInfo.ossid);
          formData.append("key", ossKey);
          formData.append("policy", ossInfo.policy);
          formData.append("ossAccessKeyId", ossInfo.ossAccessKeyId);
          formData.append("success_action_status", 201);
          formData.append("signature", ossInfo.signature);
          formData.append("file", this.textarea);
          xhr.send(formData);
上一篇:thinkphp简单三步整合系列-阿里云oss文件上传


下一篇:reduce函数