Developer Guide
File Response

    This type of response allows you to stream a file to the client's browser. For example, you can read a Note and Attachment File from the Storage Service and allow the end-user to download it.

    public ActionResponse OpenAttachment(string id)
    {
         var attch = Database.Retrieve<NoteAndAttachment>(id);
         byte[] blob = Storage.ReadFileBytes(id);
         return File(blob, attch.ContentType, attch.Name);
    }
     

    You can use the following overloads to produce a File Response:

    • File(byte[] fileContents, string contentType)
    • File(byte[] fileContents, string contentType, string fileName)
    • File(byte[] fileContents, string contentType, string fileName, bool openInline)
    • File(Stream fileStream, string contentType)
    • File(Stream fileStream, string contentType,  string fileName)
     

    The following offers an example of creating a PDF document and making it available for download.

    public ActionResponse DownloadPdf()
    {
        byte[] fileBytes = PdfGenerator.Generate("<h1>Hello World</h1>");
        return File(fileBytes, MimeContentTypes.Pdf, "myHelloWorld.pdf");
    }