问题
想从 input 输入框中拿到文件流,转换为 blob 的数据
解决
StackOverflow 上的
···html
1 |
|
MDN 示例
1 | <input type="file" onchange="previewFile()"><br> |
1 | function previewFile() { |
还有个方法是 createObjectURL
1 |
|
想从 input 输入框中拿到文件流,转换为 blob 的数据
StackOverflow 上的
···html
1 |
|
MDN 示例
1 | <input type="file" onchange="previewFile()"><br> |
1 | function previewFile() { |
还有个方法是 createObjectURL
1 |
|
记一下 JS 通过 input 加载 pdf
1 | //Step 1: Get the file from the input element |
另外一个方法,好像都差不多,不过上面的方法传值不是 { data: myData }
1 | var reader = new FileReader(); |
1 | const findData = await Assets.findOne({ |
sqlite3 就不必多介绍了,讲一下今天踩的几个坑和解决方案
https://github.com/TryGhost/node-sqlite3
最小安装用例,package.json
1 | { |
直接运行 npm i
或者 yarn
安装依赖
方法一:官方的安装方法
--target=18.1.0
中 18.1.0
改成自己的 Electron
版本号
1 | npm install sqlite3 --build-from-source --sqlite_libname=sqlcipher --sqlite=`brew --prefix` --runtime=electron --target=18.1.0 --dist-url=https://electronjs.org/headers |
方法二,先下载,后编译
1 | npm install node-gyp -g |
之所以加上 --ignore-scripts
,是因为 sqlite3
模块在 package.json
文件中写了下载时自动执行编译的脚本,如下:
1 | "scripts": { |
方法三,参数更全,自己配置 node-gyp
执行脚本路径等,具体参数需要看 node-gyp
的文档
1 | "/opt/homebrew/Cellar/node/17.5.0/bin/node" "/Users/username/Documents/Temp/sqlite3/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/Users/username/Documents/Temp/sqlite3/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/Users/username/Documents/Temp/sqlite3/node_modules/sqlite3/lib/binding/napi-v6-darwin-unknown-arm64" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=6" "--node_napi_label=napi-v6" |
头铁使用最新版本 NodeJS v17.x 时,sqlite3 安装失败,报错:
1 | gyp: name 'openssl_fips' is not defined while evaluating condition 'openssl_fips != ""' in binding.gyp while trying to load binding.gyp |
见 https://github.com/nodejs/node-gyp/issues/2534
官方说法是 Nodejs 17 版本对 openssl_fips 不太支持,或者说有复写操作。
https://github.com/nodejs/node-gyp/issues/2534#issuecomment-976089582
解决方法如下
https://github.com/nodejs/node-gyp/issues/2543#issuecomment-1072104626
node-gyp
在本地安装最新的:1 | npm install -d node-gyp@latest |
在 binding.gyp
中,添加(在顶部):
1 | { |
但是我认为最好的办法是降回正式 16.x
版本
如果你用 Homebrew
安装了 Nodejs
,那么编译的时候参数会有所变化,多出一些参数
1 | "/opt/homebrew/Cellar/node/17.5.0/bin/node" "/opt/homebrew/bin/npm" "install" "sqlite3" "--build-from-source" "--sqlite_libname=sqlcipher" "--sqlite=/opt/homebrew" "--runtime=electron" "--target=18.1.0" "--dist-url=https://electronjs.org/headers" |
会多出一个 "--sqlite=/opt/homebrew"
的参数,而你电脑上没装 sqlite3
就会产生报错导致编译失败。
解决方案,Homebrew
或者 brew
卸载 Nodejs
,用官方的 Nodejs
安装包重新安装
Mac 卸载 Nodejs
编译 Electron sqlite3
Mac 卸载 Python
1 | function isValidHttpUrl(string) { |
1 | function validURL(str) { |
后端对提交的数据进行了一些转义操作,比如 <p><b>123&456</b></p>
这样的,会被转义成 <p><b>123&456</b></p>
然后前端请求数据时,这些数据需要反转义一下
这是我目前用到的,不必担心性能问题,见后面的研究部分。
1 | // 反转义 bug@& 这样的字符 |
NestJS 接收单个文件的上传和批量多个文件上传,及上传文件添加额外参数
1 | import { |
想做一个对象检测,和自己训练模型,目前处于查资料状态,还未开始。