首页 > 解决方案 > 离子:如何使用科尔多瓦插件网络服务器在混合应用程序中本地提供文件?

问题描述

我有一个目录,其中包含一个捆绑在我的混合应用程序中的 index.html 文件。我正在使用cordova文件插件,我使用checkFile函数检查文件,我的文件都在file.dataDirectory中。我现在想通过使用https://github.com/bykof/cordova-plugin-webserver插件在我的应用程序中本地提供此文件,但我很难设置路径参数。

有一个简短的解释,我应该使用服务: https://github.com/bykof/cordova-plugin-webserver#serving-files 并使用 resolveLocalFileSystemURL

window.resolveLocalFileSystemURL('cdvfile://localhost/temporary/path/to/file.mp4', 
    function(entry) {
      console.log(entry.toURL());
    });

我确实使用它来将我的路径 index.html 文件转换为 URL() 但我不明白在哪里以及如何将这个文件传递给网络服务器插件?

我是否需要将其添加到他们拥有的https://github.com/bykof/cordova-plugin-webserver#example示例代码中?因为当我尝试这样做时,它不起作用。如果我尝试检查这个 sendRequest 函数接受什么,它会说:

sendResponse(requestId: string, responseObject: Response): Promise<any>;

在哪里

export interface Response {
    status: number;
    body: string;
    headers: {
        [key: string]: string;
    };
}
export interface Request {
    requestId: string;
    body: string;
    headers: string;
    method: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
    path: string;
    query: string;
} 

这意味着路径:字符串;在 sendResponse 但在 onRequest 中不接受。

标签: cordovaionic-frameworkionic3webservercordova-plugins

解决方案


推荐阅读