在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5/ 如何解決angular5使用g2-file-upload插件上傳文件無法賦值并且

如何解決angular5使用g2-file-upload插件上傳文件無法賦值并且報跨域錯誤?

看到簡書上有這個插件的使用介紹,就按著上面的步驟來弄。但是到提交文件給接口的時候就出現(xiàn)了報跨域訪問的問題,在接口訪問的時候也沒看到有文件流在里面。

 <input  type="file" ng2FileSelect [uploader]="uploader (change)="selectedFileOnChanged($event)" [hidden]="true">
import { Component } from '@angular/core';
import { FileUploader } from 'ng2-file-upload';

export class FileUploadertest {
 public uploader:FileUploader = new FileUploader({
    url: "http://192.168.1.250:8080/services/fileupload/temp/form.json",
    method: "POST"
 });

 selectedFileOnChanged(event) { 
      this.uploader.queue[0].onSuccess = function (response, status, headers) {
      // 上傳文件成功
      if (status == 200) {
         console.log(response)
          let tempRes = JSON.parse(response);
      } else {
          // 上傳文件后獲取服務器返回的數(shù)據(jù)錯誤
          alert("");
      }
   };
 this.uploader.queue[0].upload(); // 開始上傳 
 }

}

報錯:
圖片描述

回答
編輯回答
忠妾

你這個是跨域問題,上線的時候需要后臺做設置。簡單前臺調試的話,可以關閉Chrome的安全策略進行處理。
搜索 “chrome --disable-web-security”給你答案

2017年9月9日 00:51
編輯回答
病癮

可以在配置上傳對象的時候關閉 withCredentials 屬性

fileUploader.onAfterAddingFile = (item => {
    item.withCredentials = false
})
2017年5月13日 08:40