2011-04-20 70 views
0

是否有可能創建一個構造函數,該構造函數接受3個FileStreamResult參數。考慮到我的代碼如下,你能否告訴我是否需要創建私有方法。如果是這樣的話需要什麼代碼。是否有可能創建一個新的構造函數,其中需要3個參數FileStreamResult

public FileResult GetImage(int id) 
    { 
     const string alternativePicturePath = @"/Content/question_mark.jpg"; 
     MemoryStream stream; 
     MemoryStream streaml; 

     SubProductCategory4 z = db.SubProductCategory4.Where(k => k.SubProductCategoryFourID == id).FirstOrDefault(); 

     if ((z != null && z.Image1 != null) && (z != null && z.Image2 != null)) 
     { 

       stream = new MemoryStream(z.Image1); 
       streaml = new MemoryStream(z.Image2); 
     } 

     else 
     { 
       var path = Server.MapPath(alternativePicturePath); 

       foreach (byte item in Request.Files) 
       { 
       HttpPostedFileBase file = Request.Files[item]; 
       if (file.ContentLength == 0) 
       { 
        continue; 
       } 
      } 

      stream = new MemoryStream(); 
      var imagex = new System.Drawing.Bitmap(path); 
      imagex.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg); 
      stream.Seek(0, SeekOrigin.Begin); 

      streaml = new MemoryStream(); 
      var imagey = new System.Drawing.Bitmap(path); 
      imagey.Save(streaml, System.Drawing.Imaging.ImageFormat.Jpeg); 
      streaml.Seek(0, SeekOrigin.Begin); 
     } 



     FileStreamResult newone = new FileStreamResult(); // not sure 
            //what additional code is needed here 


     return new FileStreamResult(stream, streaml,"image/jpg"); 
     //'System.Web.Mvc.FileStreamResult' does not contain a 
     // constructor that takes 3 arguments 

FileHandle for uploading iimages。我正在使用FileHandle上傳圖片。

FileHandler.cs

public class FileHandler 
{ 
    public byte[] uploadedFileToByteArray(HttpPostedFileBase file) 
    { 
    int nFileLen = file.ContentLength; 
    byte[] result = new byte[nFileLen]; 

    file.InputStream.Read(result, 0, nFileLen); 

    return result; 
} 

} 
+0

我不明白你的問題。你是否試圖讓客戶端在同一個請求中獲得兩個下載的文件? – 2013-07-01 02:09:30

回答

0

要回答你直接問:不,你不能爲FileStreamResult創建不同的構造函數,因爲類是MVC框架(技術上,你可以搶MVC源的一部分,使這些變化,並自己編譯它,但我會建議不要這樣)。

如果你能提供更多關於你正在做什麼的信息會更好。你想連接兩個流嗎?可能有不同的方法來實現您的最終目標。

+0

Marcind - 謝謝你回覆。我試圖上傳多個數據庫圖像,引用這個鏈接。 http://stackoverflow.com/questions/5716258/unable-to-upload-multiple-db-images-with-asp-net-mvc。 – DiscoDude 2011-04-20 16:44:22

+0

@DiscoDude我不明白這個問題與圖片上傳有何關係。 FileStreamResult純粹用於下載方面。 – marcind 2011-04-20 17:34:29

+0

我編輯了上面的代碼。所以希望你能看到我想要完成的事情。簡單地說,我想爲每個產品上傳幾張圖片。我已經開始使用兩個數據庫圖像,然後一旦這可以實現,我可以進一步採取。 – DiscoDude 2011-04-21 10:22:29

相關問題