0

Is it possible to create a constructor that takes 3 arguments for FileStreamResult. Taking into account from my code below, can you tell if I need to create private method. If so what code is required for that.

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. I am using FileHandle for uploading images.

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;
 }

 }
DiscoDude
  • 617
  • 3
  • 17
  • 39
  • I don't get your question. Are you trying to make the clients get two downloaded files in the same request? – DJ. Jul 01 '13 at 02:09

1 Answers1

0

To answer your direct question: No, you cannot create a different constructor for FileStreamResult because that class is part of the MVC framework (technically you could grab the source for MVC, make the changes, and compile it yourself but I would advise against this).

It would be better if you could provide more information about what you are trying to do. Do you want to concatenate the two streams? There's probably a different way to achieve your end goal.

marcind
  • 52,944
  • 13
  • 125
  • 111
  • Marcind - thanks for replying back. I am trying to upload multiple db images, refering to this link. http://stackoverflow.com/questions/5716258/unable-to-upload-multiple-db-images-with-asp-net-mvc. – DiscoDude Apr 20 '11 at 16:44
  • @DiscoDude I don't see how this question relates to image uploads. FileStreamResult is purely for the download aspect. – marcind Apr 20 '11 at 17:34
  • I edited the code above. So hopefully you can see what I am trying to accomplish. Putting it simply I want to upload several images for each product. I have started off with two db images, then once this can be achieved, I can take it further. – DiscoDude Apr 21 '11 at 10:22