wx.arrayBufferToBase64 方法在微信小程序的基础库版本 2.4.0 起已废弃,不建议继续使用。
我们可以将ArrayBuffer 转换为 base64,使用base64-js来实现转换。具体操作如下:
1、安装base64-js,可以通过npm进行安装,或者从github获取该代码块。 代码如下:
(function (a) {
if ("object" == typeof exports && "undefined" != typeof module) module.exports = a();
else if ("function" == typeof define && define.amd) define([], a);
else {
var b;
b = "undefined" == typeof window ? "undefined" == typeof global ? "undefined" == typeof self ? this : self : global : window, b.base64js = a()
}
})(function () {
return function () {
function b(d, e, g) {
function a(j, i) {
if (!e[j]) {
if (!d[j]) {
var f = "function" == typeof require && require;
if (!i && f) return f(j, !0);
if (h) return h(j, !0);
var c = new Error("Cannot find module '" + j + "'");
throw c.code = "MODULE_NOT_FOUND", c
}
var k = e[j] = {