2016-10-12 31 views
1

我試圖發送一個文件使用aurelia-fetch-client服務器,而是要在瀏覽器控制檯下面的錯誤。 No 'Access-Control-Allow-Origin' header is present on the requested resource.,但是當我和XMLHttpRequest文件一樣上傳時。奧裏利亞JS後的二進制數據到服務器

奧裏利亞獲取客戶端的配置和使用代碼

activate() { 
    await fetch; 
    this.http = this.httpClient(); 


    this.http.configure(config => { 
     config 
     .useStandardConfiguration() 
     .withBaseUrl('http://localhost:3000') 
    }); 
} 

    makeRequest(data) { 
    this.http.fetch('upload', { 
     headers: { 
     'Content-Type': 'multipart/form-data' 
     }, 
     method: 'post', 
     body: data 
    }); 
    } 
+1

好像你還沒有你的服務器上配置CORS? – Darxtar

+0

嗨,我需要做同樣的事情,但無法找到解決方案。任何更新@llia和我的問題是在[鏈接](http://stackoverflow.com/questions/39991277/aurelia-js-fie-upload-to-server) – sibi

+0

@Darxtar你是對的,因爲我使用節點服務器我必須配置cors。 @sibi如果你正在使用'express',你可以使用cors-express模塊​​ –

回答

2

繼這裏的評論是答案:

CORS沒有在服務器上啓用,並伊利亞建議選用cors-express模塊的,如果你是使用節點。

以下資源可以爲有幫助:

http://enable-cors.org/server_expressjs.html

https://github.com/expressjs/cors

+0

tnx爲回覆@darxtar – sibi

+0

似乎服務器團隊得到配置的Cors,可能問題是表單視圖/模型。任何人都可以檢查這個問題[鏈接](http://stackoverflow.com/questions/39991277/aurelia-js-fie-upload-to-server) – sibi