Skip to content

Commit fe29a4c

Browse files
committed
download file code refactor
1 parent 5caadb0 commit fe29a4c

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

LearningHub.Nhs.WebUI/Services/FileService.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,26 @@ public async Task<FileDownloadResponse> DownloadFileAsync(string filePath, strin
145145

146146
try
147147
{
148-
// Directly download the entire file as a stream
149-
var response = await file.DownloadAsync();
150-
return new FileDownloadResponse
148+
if (fileSize <= 900 * 1024 * 1024)
151149
{
152-
Content = response.Value.Content,
153-
ContentType = properties.Value.ContentType,
154-
ContentLength = fileSize,
155-
};
150+
// Directly download the entire file as a stream
151+
var response = await file.DownloadAsync();
152+
return new FileDownloadResponse
153+
{
154+
Content = response.Value.Content,
155+
ContentType = properties.Value.ContentType,
156+
ContentLength = fileSize,
157+
};
158+
}
159+
else
160+
{
161+
return new FileDownloadResponse
162+
{
163+
Content = await file.OpenReadAsync(),
164+
ContentType = properties.Value.ContentType,
165+
ContentLength = fileSize,
166+
};
167+
}
156168
}
157169
catch (Exception ex)
158170
{

0 commit comments

Comments
 (0)