summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorivarlovlie <git@ivarlovlie.no>2023-01-16 19:42:07 +0100
committerivarlovlie <git@ivarlovlie.no>2023-01-16 19:42:07 +0100
commit8a7c318f6273c51ea1b96c87f98b0320ef339e16 (patch)
tree260735d25927b33edc91bcb4c60c0bfe278e6c5c
parent9d0278930469c04dfb6dcca2f535d9b38abe17bb (diff)
downloadblob-bin-8a7c318f6273c51ea1b96c87f98b0320ef339e16.tar.xz
blob-bin-8a7c318f6273c51ea1b96c87f98b0320ef339e16.zip
feat: Check if file exists on disk
-rw-r--r--src/Program.cs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/Program.cs b/src/Program.cs
index 51ef4b0..29b0fe1 100644
--- a/src/Program.cs
+++ b/src/Program.cs
@@ -244,11 +244,12 @@ async Task<IResult> GetFile(HttpContext context, Db db, string id, bool download
db.SaveChanges();
}
- var reader = await System.IO.File.ReadAllBytesAsync(
- Path.Combine(
- Tools.GetFilesDirectoryPath(), file.Id.ToString()
- )
- );
+ var path = Path.Combine(Tools.GetFilesDirectoryPath(), file.Id.ToString());
+ if (!System.IO.File.Exists(path)) {
+ return Results.NotFound();
+ }
+
+ var reader = await System.IO.File.ReadAllBytesAsync(path);
return download ? Results.File(reader, file.MimeType, file.Name) : Results.Bytes(reader, file.MimeType);
}