如何对图像进行 Base64 处理,以便适合使用 NativeScript 获取模块发送?
这是使用测试服务器的情况的基本演示
"use strict";
var imageSourceModule = require("image-source");
function navigatingTo(args) {
var page = args.object;
// using icon.png from the template app from res://icon
var imgSrc = imageSourceModule.fromResource("icon");
var imageAsBase64 = imgSrc.toBase64String("PNG");
fetch("https://httpbin.org/post", {
method: "POST",
headers: { "Content-Type": "application/octet-stream" },
body: imageAsBase64
}).then(function (r) { return r.json(); }).then(function (result) {
console.log("Base64String: " + result.data);
// for (var key in result) {
// if (result.hasOwnProperty(key)) {
// var element = object[result];
// console.log(key);
// console.log(element);
// console.log("------")
// }
// }
}, function (e) {
console.log("Error occurred " + e);
});
}
exports.navigatingTo = navigatingTo;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)