my ActionResult provides a StreamContent file in the HttpResponseMessage result.Content. Now I would like to track the state of the download, to delete the file immediately after it was downloaded.
I found solutions that use the ByteStream, which split the file into chunks but that lacks the possibilities to provide a HttpStatusCode and other information in case some authorization tests deny the request.
This is my current controller:
[HttpGet]
public HttpResponseMessage GetZipDownload(string token, string guid)
{
if (!dOps.ValidateToken(token))
{
return Request.CreateResponse(HttpStatusCode.Unauthorized,
new HttpError("Unauthorized"));
}
Device device = dOps.GetDeviceFromToken(auth);
AssetOperations assetOps = new AssetOperations();
HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
FileStream file = assetOps.GetZip(guid);
var content = new StreamContent(file);
result.Content = content;
result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
result.Content.Headers.Add("Connection", "Keep-Alive");
result.Content.Headers.Add("Content-Length", (file.Length).ToString());
return result;
}
Before I dig deeper into the ByteStream solution, I would like to ask if anybody probably knows about a reliable solution for ASP.NET MVC 5.