2013-06-27 40 views
1

我想將上傳的文件上傳到我的mvc 4.0應用程序運行的地方以及另一臺由基於Linux的服務器供電的服務器。我想上傳文件到tomcat服務器下的目錄(例如:KGS/assets /)。我可以通過下面的代碼從asp.net mvc 4.0應用程序將上傳的文件寫入linux服務器

public ActionResult Upload(string qqfile, int id) 
     { 
      //resim ekliyor 
      const string path = @"C:\Temp\"; 
      const string kgsPath [email protected]"\\"; 
      try 
      { 
       var stream = Request.InputStream; 
       string file; 
       if (String.IsNullOrEmpty(Request["qqfile"])) 
       { 
        // IE 
        HttpPostedFileBase postedFile = Request.Files[0]; 
        stream = postedFile.InputStream; 
        file = Path.Combine(path, System.IO.Path.GetFileName(Request.Files[0].FileName)); 
       } 
       else 
       { 
        //Webkit, Mozilla 
        file = Path.Combine(path, qqfile); 
       } 

       var buffer = new byte[stream.Length]; 
       stream.Read(buffer, 0, buffer.Length); 
       System.IO.File.WriteAllBytes(file, buffer); 

      } 
      catch (Exception ex) 
      { 
       return Json(new { success = false, message = ex.Message }, "application/json"); 
      } 
      return Json(new { success = true }, "text/html"); 
     } 

上傳文件下載到本地服務器是否有反正或者接近實現這一目標,或者這是不可能做?

回答

0

您必須公開某種方式將文件存儲在您的ASP.NET應用程序可以使用的Linux服務器上。這可能是Samba或NFS共享,FTP帳戶,Web服務等。您選擇的存儲機制將決定您如何在其中存儲文件。

另一種選擇是使用類似rsync的文件來保持兩個地方的文件同步。你的.NET應用程序將不知道這一點,所以不需要編碼。

相關問題