Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resource interpreted as Document but transferred with MIME type application/pdf

See the following code:

Controller:

public ActionResult GetPDF()
{
    byte[] pdf = GetPdfFromDatabase();
    return new FileContentResult(reportData, "application/pdf");
}

View:

<iframe src="@Url.Action("GetPDF","Account")" width="600" height="500"></iframe>

Javascript Console:

enter image description here

Each time you load a page, show this warning !!!

like image 607
Matheus Miranda Avatar asked Sep 21 '16 15:09

Matheus Miranda


3 Answers

An iframe requests the resource mentioned in src attribute with a content type text/html. So this message only says "I requested html but server responded with pdf"

like image 114
Burak SARICA Avatar answered Nov 15 '22 15:11

Burak SARICA


For who come across this topic. (Me too.) For best solution is you need to create HTML page to act as iframe landing page to show PDF content.

This is example html. I just extract from chrome.

<html><body style="background-color: rgb(38, 38, 38); height: 100%; width: 100%; overflow: hidden; margin: 0px;"><embed width="100%" height="100%" name="plugin" id="plugin" src="your_pdf_url" type="application/pdf"></body></html>

Just replace your_pdf_url to your real url. I just add this html as middleware in Laravel and show this HTML so Chrome will not warning anymore. You can use this html as base and create better pdf landing page such as custom loading.

like image 23
EThaiZone Avatar answered Nov 15 '22 15:11

EThaiZone


I believe the warning can't be ignored.

An alternative I found to this problem, use the object tag, like this:

<object data="your-data-base-64" type="application/pdf"></object>

and if you using angularJS, to prevent error on console do:

<object ng-attr-data="your-data-base-64" type="application/pdf"></object>

like image 6
Márcio Rossato Avatar answered Nov 15 '22 17:11

Márcio Rossato