Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Access is Denied" when embedding file from blob URL in IE

I have a web service that is sending the client a file as an arraybuffer which is then read into a blob object:

$scope.contentType = response.headers["content-type"];
$scope.file = new Blob([response.data], { type: $scope.contentType });
$scope.fileUrl = URL.createObjectURL($scope.file);
$scope.content = $sce.trustAsResourceUrl($scope.fileUrl);

I am using an object tag as the container:

<object id="documentContainer" ng-show="loaded" ng-attr-type="{{contentType}}" ng-attr-data="{{content}}" class="document-container"></object>

This works great in FF, chrome, mobile browsers, web browsers developed by alien species who have never had contact with humanity, etc., but not in IE.

When the data parameter of the object tag is set, IE responds in the console with

Error: Access is denied.

This seems to be some sort of security feature in IE where it doesn't want to use the file as a source because it resides on the client machine. It prohibits access even if you use javascript to create a brand new dom element with the data source set.

Microsoft provides their own blob methods like msSaveOrOpenBlob, but I need to be able to embed the file in the browser, not prompt the user to open the file in an external application.

Does anyone know of a workaround or way to embed the blob, which can be a wide variety of file types, in IE? I would hate to have to drastically refactor the web service and front end code just to accommodate IE, but it is looking like that might have to be the case.

like image 445
mrturburdaugh Avatar asked Jun 12 '15 18:06

mrturburdaugh


1 Answers

I think the answer is "no". Our site generates PDF on the fly but we sniff the browser for what can be done with the returned PDF.

Example: http://www.cloudformatter.com/CSS2Pdf.Demos.Structures

If you are on Chrome you could select the "Embed PDF" here and it works like a charm ... if you are on IE, even if you select "Embed", it downloads the file. Because IE cannot and we just reroute anyone on IE to the download code.

http://caniuse.com/#feat=datauri

And don't get us started on what else is wrong on IE, several of the pages just broke because IE stopped serializing end tags for some "p" tags in the document.

like image 165
Kevin Brown Avatar answered Oct 26 '22 09:10

Kevin Brown