From 5a14fb74524f6c6f8358a6326bf9c946294d609a Mon Sep 17 00:00:00 2001 From: Hisham Bin Ateya Date: Thu, 7 Nov 2024 21:52:08 +0300 Subject: [PATCH] Extract PDF on file system instead of memory (#16958) --------- Co-authored-by: Mike Alhayek --- .../Services/PdfMediaFileTextProvider.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media.Indexing.Pdf/Services/PdfMediaFileTextProvider.cs b/src/OrchardCore.Modules/OrchardCore.Media.Indexing.Pdf/Services/PdfMediaFileTextProvider.cs index 11f1bd98dac..3cb4917a52e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media.Indexing.Pdf/Services/PdfMediaFileTextProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media.Indexing.Pdf/Services/PdfMediaFileTextProvider.cs @@ -11,16 +11,15 @@ public async Task GetTextAsync(string path, Stream fileStream) // https://github.com/UglyToad/PdfPig/blob/master/src/UglyToad.PdfPig.Core/StreamInputBytes.cs#L45. // Thus if it isn't, which is the case with e.g. Azure Blob Storage, we need to copy it to a new, seekable // Stream. - MemoryStream seekableStream = null; + FileStream seekableStream = null; try { if (!fileStream.CanSeek) { - // Since fileStream.Length might not be supported either, we can't preconfigure the capacity of the - // MemoryStream. - seekableStream = new MemoryStream(); - // While this involves loading the file into memory, we don't really have a choice. + seekableStream = new FileStream(Path.GetTempFileName(), FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, 4096, FileOptions.DeleteOnClose); + await fileStream.CopyToAsync(seekableStream); + seekableStream.Position = 0; }