I have two situations where we return data (for example to a client requesting a video) from a ServiceStack API.
For streaming a file:
var fs = new FileStream(video.FileSystemAddress, FileMode.Open, FileAccess.Read);
return new HttpResult(fs, video.MimeType);
For downloading a file:
var fileStream = new FileStream(video.FileSystemAddress, FileMode.Open, FileAccess.Read);
return new GetResourceResponse(fileStream, video.MimeType, video.FileName);
Are the file streams automatically disposed by the framework or is this something I need to do?
In the example about, GetResourceResponse
implements IHasOptions, IStreamWriterAsync, IDisposable
:
public async Task WriteToAsync(Stream responseStream, CancellationToken token = new CancellationToken())
{
if (stream == null)
return;
await stream.CopyToAsync(responseStream, token);
}