Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

Web API - Stream large file to client

public HttpResponseMessage GetFile(string id)
{
    if (String.IsNullOrEmpty(id))
        return Request.CreateResponse(HttpStatusCode.BadRequest);

    string fileName;
    string localFilePath;
    int fileSize;

    localFilePath = getFileFromID(id, out fileName, out fileSize);

    HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
    response.Content = new StreamContent(new FileStream(localFilePath, FileMode.Open, FileAccess.Read));
    response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment");
    response.Content.Headers.ContentDisposition.FileName = fileName;
    response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/pdf");

    return response;
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: how to handle array getter setter in c# of string type 
Csharp :: remotefx 3d video adapter warning 
Csharp :: delegates in c# 
Csharp :: difference between all logging framework .NET Core? 
Csharp :: flutter failed asertion 
Csharp :: split a datatable based on number of rows 
Csharp :: how to get variable value in properties file in inspector unity 
Csharp :: math round to next integer c# 
Csharp :: visual studio private field underscore 
Csharp :: unity next level trigger 
Csharp :: select vs where linq 
Csharp :: telerik mvc grid required field 
Csharp :: c# get executing method name 
Csharp :: Visual Studio - Summary Tag Comments - Optional Params 
Csharp :: Stop Unity Wait Time with Button 
Csharp :: datagridview show noti each row column 
Csharp :: c# make two checkbox uncheckable both 
Csharp :: json string to JObject object c# camelCasing key .net 
Csharp :: how to pass id to modal in asp.net mvc 
Csharp :: isdaylightsavingtime in c# 
Csharp :: boucle C# 
Csharp :: unity having virtual start 
Csharp :: method declaration in c# 
Csharp :: nunit return parameter 
Csharp :: C# Read Excel columns header return to list 
Csharp :: how can datetimepicker accept hour as well 
Csharp :: return array in c# 
Csharp :: call ienumerator unity 
Csharp :: ocr library for c# 
Csharp :: c# optional parameters using 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =