使用小程序的文件接口:FileSystemManager.writeFileSync
sourceURI = parser.getDependency('bufferView', source.bufferView).then(function(
bufferView) {
isObjectURL = true;
var sourceURI = `${wx.env.USER_DATA_PATH}/${Date.now()}.png`
const res = fs.writeFileSync(sourceURI, bufferView, 'utf8')
return sourceURI
// var blob = new Blob([bufferView], {
// type: source.mimeType
// });
// sourceURI = URL.createObjectURL(blob);
// return sourceURI;
});
resolveURL里面添加 if (/^wxfile:.*$/i.test(url)) return url; 否则真机运行会出错
function resolveURL(url, path) {
// Invalid URL
if (typeof url !== 'string' || url === '') return '';
// Host Relative URL
if (/^https?:\/\//i.test(path) && /^\//.test(url)) {
path = path.replace(/(^https?:\/\/[^\/]+).*/i, '$1');
}
// Absolute URL http://,https://,//
if (/^(https?:)?\/\//i.test(url)) return url;
// Data URI
if (/^data:.*,.*$/i.test(url)) return url;
// Blob URL
if (/^blob:.*$/i.test(url)) return url;
// wxfile URL
if (/^wxfile:.*$/i.test(url)) return url; // 添加
// Relative URL
return path + url;
}