We have the following code for downloading blobs from Azure:
ICloudBlob reference = _container.GetBlobReferenceFromServer(blobName);
Stream stream = return reference.OpenRead();
HttpResult httpResult = new HttpResult(stream, mimeType);
if (asAttachment)
{
string createdOnString = dbBlob.CreatedOn.ToString("R").Replace(",", "");
httpResult.Options.Add(HttpHeaders.ContentDisposition, $@"attachment; filename=""{fileName}""; size={stream.Length}; creation-date={createdOnString}; modification-date={createdOnString}; read-date={createdOnString}");
}
return httpResult;
When downloading a large file (1.7 GB), this results in an OutOfMemoryException:
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
at ServiceStack.HttpRequestExtensions.ToStatusCode(Exception ex)
at ServiceStack.ServiceStackHost.HandleUncaughtException(IRequest httpReq, IResponse httpRes, String operationName, Exception ex)
at ServiceStack.HostContext.RaiseAndHandleUncaughtException(IRequest httpReq, IResponse httpRes, String operationName, Exception ex)
at ServiceStack.HttpResponseExtensionsInternal.WriteToResponse(IResponse response, Object result, ResponseSerializerDelegate defaultAction, IRequest request, Byte[] bodyPrefix, Byte[] bodySuffix)
at ServiceStack.HttpResponseExtensionsInternal.WriteToResponse(IResponse httpRes, IRequest httpReq, Object result, Byte[] bodyPrefix, Byte[] bodySuffix)
at ServiceStack.Host.RestHandler.<>c__DisplayClass5.<ProcessRequestAsync>b__0(Object response)
at ServiceStack.Host.Handlers.ServiceStackHandlerBase.HandleResponse(Object response, Func`2 callback, Func`2 errorCallback)
What are we doing wrong?
The site is hosted on Azure in an App Service (ASP.NET).