2016-09-14 47 views
0

我想用api上傳文件,但也需要發'ID'。 相同的代碼在本地工作,但不在IIS上工作。用api上傳文件不能在IIS上工作

 [HttpPost("{id}")] 
     [Route("Upload/{id}")] 
     public async Task<IActionResult> Upload(int id) 
     { 
      using (var client = new HttpClient()) 
      { 
       foreach (var file in Request.Form.Files) 
       { 
        // . . . more logic  
       } 
      } 

      return new OkResult(); 
     } 

在本地: enter image description here 在IIS enter image description here

+0

在IIS的情況下Referer是不同的。你有一個名爲dataset的虛擬目錄嗎? – sachin

+0

同一頁面上的所有其他api-s工作正常。只是這個有問題。 – Raskolnikov

+0

請嘗試設置HttpClient的發佈內容的內容類型。請參閱http://stackoverflow.com/questions/27425043/upload-image-using-httpclient和http://stackoverflow.com/questions/16416601/c-sharp-httpclient-4-5-multipart-form-data-在iis中上傳 –

回答

-1

我找到的解決方案,這是非常愚蠢的。

在TypeScript中的客戶端上。

this.$upload.upload({ 
       url: '/api/transfer/upload/' + this.id, 
       method: 'POST', 
       headers: { 'Content-Type': 'multipart/form-data' }, 
       file: file, 
       fileName: file.name, 
      })... 

而不是

this.$upload.upload({ 
       url: 'api/transfer/upload/' + this.id, 
       method: 'POST', 
       headers: { 'Content-Type': 'multipart/form-data' }, 
       file: file, 
       fileName: file.name, 
      }) 

JUST ONE SLASH的URL路徑和不工作的IIS!