【问题标题】:Loading files in-browser from a server and .djvu files do not load从服务器加载浏览器中的文件并且 .djvu 文件不加载
【发布时间】:2017-02-16 18:37:34
【问题描述】:

我正在编写一个在 iframe 中加载文件的应用程序。它适用于 .pdf 和图像文件,但不适用于 .djvu 文件。 文件地址正在通过 AngularJS (v1.2) 传递到 iframe

当我尝试加载 .djvu 文件时,我收到 404.3 Not found 错误。下面是正在渲染的视图:

Index.cshtml

@model string
<div ng-controller="FileBrowserController" ng-init="getFiles('@Model')" style="width:100%;position:absolute;top:0;bottom:0;">
    <div class="row text-center" ng-show="showButtons" style="margin-bottom:5px">
        <div class="col-xs-1">
            <!--<button ng-show="f"  type="button" class="btn btn-sm btn-primary" ng-click="deleteFile()" ng-confirm-click="Are you sure that you want to delete this file?">Delete</button>-->
        </div>
        <div class="col-xs-10">
            <button ng-show="showButtons" type="button" class="btn btn-sm btn-primary" ng-disabled="currentFile.sortOrder==1" ng-click="previousFile()">Previous</button>
            <select ng-model="currentFile" ng-show="showButtons"
                    ng-options="file.sortOrder for file in files"
                    ng-change="setFile()"></select>
            <button ng-show="showButtons" type="button" class="btn btn-sm btn-primary" ng-disabled="currentFile.sortOrder==files.length" ng-click="nextFile()">Next</button>
        </div>
        <div class="col-xs-1"> </div>

    </div>

    <iframe style="min-height:100%;min-width:100%" ng-src="{{currentFileUrl}}"></iframe> 

    <!-- Modal -->
    <div class="modal fade" id="getdjvuPluginModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="modalLabel">Get DjVu Viewer browser plugin</h4>
                </div>
                <div class="modal-body">
                    <div>
                        <p>It doesn't look like you have installed a plugin to view ".djvu" files with.</p>
                    </div>
                    <p>
                        <strong>If you are using Internet Explorer, Firefox, or Safari:</strong>
                    </p>
                    <p>
                        Download the DjVu Browser Plug-in for Internet Explorer, Firefox and Safari. Please click <strong><a ng-href="{{djvuPluginUrl}}" target="_blank">here</a></strong> to go to the download page.
                    </p>
                    <p>
                        <strong>If you are using Chrome:</strong>
                    </p>
                    <p>
                        Download the DjVu Viewer Extension for Google Chrome. Please click <strong><a ng-href="{{chromePluginUrl}}" target="_blank">here</a></strong> to go to the Google Play store and download the plugin.
                    </p>
                    <hr />
                    <div>If you already have the plugin installed and think you are seeing this message in error then please reload the page.</div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

</div>

@Scripts.Render("~/app/documents/detectDjVuPlugin.js")

AngularJS 将 url 作为可信资源 url 传递给 iframe

$scope.currentFileUrl = $sce.trustAsResourceUrl($scope.currentFile.fileUrl);

我已尝试按照推荐的步骤操作:

  • 向 Web.config 添加了处理程序

<system.webServer> ... <staticContent> <!-- .DjVu files handler --> <mimeMap fileExtension=".djvu" mimeType="image/vnd.djvu"/> <mimeMap fileExtension=".djv" mimeType="image/vnd.djvu"/> </staticContent>

  • 向 IIS 添加 MIME 类型
  • 检查djvu插件是否已安装(我可以从互联网上加载djvu文件)
  • 将文件 url 设置为 &lt;embed&gt; 标签的来源 该应用在 .Net 4.0、C# 后端和 AngularJS 上运行。

我不知道如何加载。

【问题讨论】:

    标签: javascript asp.net angularjs mime-types djvu


    【解决方案1】:

    经过多次试验和错误,我得到了这个工作。最后我不得不从使用 IIS Express 切换到完整的 IIS,并在那里添加 MIME 类型。

    值得注意的是,当 mimeMap 添加到应用程序的 web.config 时,Internet Explorer 11 没有检测到它并且无法显示 djvu 文件(与以前相同的 404.3 错误),但 Chrome 已经足够高兴了。

    为了在 IE 11 中显示 .djvu 文件,我必须将 mimeMap 添加到根站点或应用程序主机。这可以通过 IIS 管理器完成;或分别通过 wwwroot Web.Config 或 applicationhost.config 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-26
      • 1970-01-01
      相关资源
      最近更新 更多