0

I'm using Azure blob storage to house images and DOMPdf to create PDF files. The issue I'm facing is that DOMPdf will not "Download files" to display them. My current controller, contacts Azure blob storage, grabs the file and spits it out as a download.

Instead, I have tried to use the response()->file() method in Laravel to display the image instead:

// Assume $file holds the file content from Azure Blob Storage
\Illuminate\Support\Facades\File::append(Storage::disk('local')->path("chunks/{$fileToken}"), $file);
$mimeType = mime_content_type(Storage::disk('local')->path("chunks/{$fileToken}"));


# Check if we can render this as an image
if (in_array($mimeType, ['image/jpeg','image/gif','image/png','image/bmp','image/svg+xml'])) {
    $headers = [
        'Content-Type' => $mimeType,
        'Content-Disposition' => sprintf('inline; filename="%s"', $realPath->filename)
    ];

    $response = response()->file(Storage::disk('local')->path("chunks/{$fileToken}"), $headers);

    # Delete from local disk
    \Illuminate\Support\Facades\File::delete(Storage::disk('local')->path("chunks/{$fileToken}"));

     return $response;
}

# Delete from local disk
\Illuminate\Support\Facades\File::delete(Storage::disk('local')->path("chunks/{$fileToken}"));

// Do normal download functionality

Now, the mime_content_type successfully identifies the PNG I am trying, it creates the file in the chunks directory and if I remove the delete, I can open it as the PNG perfectly fine. The issue I'm getting is the browser is not rendering the image. Infact, it is rendering the headers?

image

How can I render this image out to the browser so I can then access the image in DOMPdf?

Jaquarh
  • 6,493
  • 7
  • 34
  • 86
  • I guess you really need to concentrate on the showing of an image only. Try to make a complete code example, that reproduces the problem. – KIKO Software Oct 13 '22 at 09:11
  • That will reproduce the problem, just put any file content inside of a variable named `$data` with that code, replace the `$fileToken` with any value and its reproduceable - but I've earmarked the question as related to DomPDF as I guess it solves the current issue that this is kind of associated too and I appreciate the help :D @KIKOSoftware – Jaquarh Oct 13 '22 at 09:16

0 Answers0