Requirement is to allow user to upload and download large files upto 2GB from Angular 5 based SPA to google cloud storage or file storage based on deployment. Flow is SPA->Asp.NetCore WebAPI -> Google Cloud Storage.
We don't want to expose underlying storage provider to the user whether it is file system or google file storage.
The user authorization is happening at ASP.Net Core Web API layer so requests and response needs to go through web api
We have used Memory stream to buffer the response from Cloud Storage and than passed that stream to the response. We don't want to buffer the response on web server as file sizes could be very large. Below is the code which works for us but requires full stream to be buffered before sending the response
[HttpGet]
[Route("filedownload")]
public async Task<IActionResult> GetFile4(string fileName)
{
var outputFile = new MemoryStream();
string objectName = "objectname";
if (!string.IsNullOrEmpty(fileName))
objectName = fileName;
var downloadObjectOptions = new DownloadObjectOptions();
await helper._client.DownloadObjectAsync(helper._bucketName, objectName, outputFile,downloadObjectOptions);
outputFile.Position = 0;
return new FileStreamResult(outputFile, "text/csv");
}