cordova - 离子:如何使用科尔多瓦插件网络服务器在混合应用程序中本地提供文件?
问题描述
我有一个目录,其中包含一个捆绑在我的混合应用程序中的 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 中不接受。
解决方案
推荐阅读
- kubernetes - 非 Root 用户 Helm 和 AKS
- javascript - 将对象数组的数组注入到对象数组中
- selenium - 发布管道上的 Selenium Test .net core 3.1 具有框架不匹配
- x86 - 移位 AVX2 寄存器中的值,从另一个寄存器中获取最后一个
- ios - 使用 AVFoundation 拍摄的图像上的污点
- postgresql - 我的 postgresql docker 容器正在使用所有的 ram 并且表现得很奇怪
- amazon-web-services - 无服务器 (AWS) – CORS
- ios - 带有使用数组字典的部分的 SwiftUI 列表
- c++ - 如何保持 QtCreator 运行路径?
- flutter - 从导航器设置 TextEditingController 的值